Test Failed
Push — master ( bba2de...93620d )
by Andreas
08:43
created

midcom_helper_reflector::is_same_class()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.helper.reflector
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use midgard\portable\storage\connection;
10
use midgard\portable\api\mgdobject;
11
12
/**
13
 * The Grand Unified Reflector
14
 *
15
 * @package midcom.helper.reflector
16
 */
17
class midcom_helper_reflector extends midcom_baseclasses_components_purecode
18
{
19
    public $mgdschema_class;
20
21
    /**
22
     * @var midgard_reflection_property
23
     */
24
    protected $_mgd_reflector;
25
26
    protected $_dummy_object;
27
28
    private static $_cache = [
29
        'l10n' => [],
30
        'instance' => [],
31
        'title' => [],
32
        'name' => [],
33
        'fieldnames' => [],
34
        'object_icon_map' => null,
35
        'create_icon_map' => null
36
    ];
37
38
    /**
39
     * Constructor, takes classname or object, resolved MgdSchema root class automagically
40
     *
41
     * @param string|mgdobject $src classname or object
42
     */
43 192
    public function __construct($src)
44
    {
45 192
        parent::__construct();
46
47
        // Resolve root class name
48 192
        $this->mgdschema_class = self::resolve_baseclass($src);
49
        // Could not resolve root class name
50 192
        if (empty($this->mgdschema_class)) {
51
            // Handle object vs string
52
            $original_class = (is_object($src)) ? get_class($src) : $src;
53
            throw new midcom_error("Could not determine MgdSchema baseclass for '{$original_class}'");
54
        }
55
56
        // Instantiate midgard reflector
57
        $this->_mgd_reflector = new midgard_reflection_property($this->mgdschema_class);
58
59 192
        // Instantiate dummy object
60
        $this->_dummy_object = new $this->mgdschema_class;
61
    }
62 192
63
    /**
64
     * Get cached reflector instance
65 192
     *
66 192
     * @param mixed $src Object or classname
67
     * @return static
68
     */
69
    public static function &get($src)
70
    {
71
        $identifier = get_called_class() . (is_object($src) ? get_class($src) : $src);
72
73
        if (!isset(self::$_cache['instance'][$identifier])) {
74 273
            self::$_cache['instance'][$identifier] = new static($src);
75
        }
76 273
        return self::$_cache['instance'][$identifier];
77
    }
78 273
79 37
    /**
80
     * Get object's (mgdschema) fieldnames.
81 273
     *
82
     * @param object $object Object The object to query
83
     */
84
    public static function get_object_fieldnames($object) : array
85
    {
86
        if (!is_object($object)) {
87
            throw new midcom_error('Invalid parameter type');
88
        }
89 104
        $classname = get_class($object);
90
        $metadata = false;
91 104
92
        if (midcom::get()->dbclassloader->is_midcom_db_object($object)) {
93
            $classname = $object->__mgdschema_class_name__;
94 104
        } elseif ($object instanceof midcom_helper_metadata) {
95 104
            $metadata = true;
96
            $classname = $object->object->__mgdschema_class_name__;
97 104
        }
98 94
99 85
        if (is_subclass_of($classname, mgdobject::class)) {
100 74
            $cm = connection::get_em()->getClassMetadata($classname);
101 74
            return $cm->get_schema_properties($metadata);
0 ignored issues
show
introduced by
The method get_schema_properties() does not exist on Doctrine\ORM\Mapping\ClassMetadata. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
            return $cm->/** @scrutinizer ignore-call */ get_schema_properties($metadata);
Loading history...
102
        }
103
        return array_keys(get_object_vars($object));
104 104
    }
105 104
106 104
    /**
107
     * @param string $property
108 4
     * @param boolean $metadata
109
     */
110
    public function property_exists($property, $metadata = false) : bool
111
    {
112
        return $this->_mgd_reflector->property_exists($property, $metadata);
113
    }
114
115 229
    /**
116
     * Gets a midcom_helper_l10n instance for component governing the type
117 229
     */
118
    public function get_component_l10n() : midcom_services_i18n_l10n
119
    {
120
        // Use cache if we have it
121
        if (isset(self::$_cache['l10n'][$this->mgdschema_class])) {
122
            return self::$_cache['l10n'][$this->mgdschema_class];
123 67
        }
124
        $midcom_dba_classname = midcom::get()->dbclassloader->get_midcom_class_name_for_mgdschema_object($this->_dummy_object);
125
        if (empty($midcom_dba_classname)) {
126 67
            // Could not resolve MidCOM DBA class name, fallback early to our own l10n
127 63
            debug_add("Could not get MidCOM DBA classname for type {$this->mgdschema_class}, using our own l10n", MIDCOM_LOG_INFO);
128
            self::$_cache['l10n'][$this->mgdschema_class] = $this->_l10n;
129 11
            return $this->_l10n;
130 11
        }
131
132 1
        if ($component = midcom::get()->dbclassloader->get_component_for_class($midcom_dba_classname)) {
133 1
            self::$_cache['l10n'][$this->mgdschema_class] = $this->_i18n->get_l10n($component);
134 1
            return self::$_cache['l10n'][$this->mgdschema_class];
135
        }
136
137 11
        debug_add("Could not resolve component for DBA class {$midcom_dba_classname}, using our own l10n", MIDCOM_LOG_INFO);
138 11
        self::$_cache['l10n'][$this->mgdschema_class] = $this->_l10n;
139 11
        return $this->_l10n;
140
    }
141
142
    /**
143
     * Get the localized label of the class
144
     *
145
     * @todo remove any hardcoded class names/prefixes
146
     */
147
    public function get_class_label() : string
148
    {
149
        $component_l10n = $this->get_component_l10n();
150
        $use_classname = $this->mgdschema_class;
151
152 67
        $midcom_dba_classname = midcom::get()->dbclassloader->get_midcom_class_name_for_mgdschema_object($use_classname);
153
154 67
        if (!empty($midcom_dba_classname)) {
155 67
            $use_classname = $midcom_dba_classname;
156
        }
157 67
158
        $use_classname = preg_replace('/_(db|dba)$/', '', $use_classname);
159 67
160 67
        $label = $component_l10n->get($use_classname);
161
        if ($label == $use_classname) {
162
            // Class string not localized, try Bergie's way to pretty-print
163 67
            $classname_parts = explode('_', $use_classname);
164
            if (count($classname_parts) >= 3) {
165 67
                // Drop first two parts of class name
166 67
                array_shift($classname_parts);
167
                array_shift($classname_parts);
168 67
            }
169 67
            // FIXME: Remove hardcoded class prefixes
170
            $use_label = preg_replace('/(openpsa|notifications)_/', '', implode('_', $classname_parts));
171 67
172 67
            $use_label = str_replace('_', ' ', $use_label);
173
            $label = $component_l10n->get($use_label);
174
            if ($use_label == $label) {
175 67
                $label = ucwords($use_label);
176
            }
177 67
        }
178 67
        return $label;
179 67
    }
180 62
181
    /**
182
     * Get property name to use as label
183 67
     *
184
     * @return string name of property to use as label (or false on failure)
185
     */
186
    public function get_label_property()
187
    {
188
        $midcom_class = midcom::get()->dbclassloader->get_midcom_class_name_for_mgdschema_object($this->mgdschema_class);
189
        $obj = ($midcom_class) ? new $midcom_class : new $this->mgdschema_class;
190
191 25
        if (method_exists($obj, 'get_label_property')) {
192
            return $obj->get_label_property();
193 25
        }
194 25
        if (midcom::get()->dbfactory->is_a($obj, midcom_db_person::class)) {
195
            return ['rname', 'id'];
196 25
        }
197 2
        if ($this->get_title_property_nonstatic($obj) !== false) {
0 ignored issues
show
introduced by
The condition $this->get_title_propert...nstatic($obj) !== false is always true.
Loading history...
198
            return $this->get_title_property_nonstatic($obj);
199 23
        }
200 1
        if ($this->get_name_property_nonstatic($obj) !== false) {
201
            return $this->get_name_property_nonstatic($obj);
202 22
        }
203 17
        return 'guid';
204
    }
205 6
206 5
    /**
207
     * Get the object label property value
208 2
     *
209
     * @param mixed $object    MgdSchema object
210
     * @return string       Label of the object
211
     */
212
    public function get_object_label($object)
213
    {
214
        if ($object instanceof mgdobject) {
215
            try {
216
                $obj = midcom::get()->dbfactory->convert_midgard_to_midcom($object);
217 54
            } catch (midcom_error $e) {
218
                return false;
219 54
            }
220
        } else {
221 2
            $obj = $object;
222
        }
223 2
        if (method_exists($obj, 'get_label')) {
224
            return $obj->get_label();
225
        }
226 52
227
        $properties = array_flip($obj->get_properties());
228 54
        if (empty($properties)) {
229 42
            debug_add("Could not list object properties, aborting", MIDCOM_LOG_ERROR);
230
            return false;
231
        }
232 14
        if (isset($properties['title'])) {
233 14
            return $obj->title;
234
        }
235
        if (isset($properties['name'])) {
236
            return $obj->name;
237 14
        }
238 12
        if ($obj->id > 0) {
239
            return $this->get_class_label() . ' #' . $obj->id;
240 3
        }
241 2
        return '';
242
    }
243 1
244
    /**
245
     * Get the name of the create icon image
246 1
     *
247
     * @param string $type  Name of the type
248
     */
249
    public static function get_create_icon($type) : string
250
    {
251
        if (null === self::$_cache['create_icon_map']) {
252
            self::$_cache['create_icon_map'] = self::_get_icon_map('create_type_magic', 'file-o');
253
        }
254 28
255
        $icon_callback = [$type, 'get_create_icon'];
256 28
        switch (true) {
257 1
            // class has static method to tell us the answer ? great !
258
            case (is_callable($icon_callback)):
259
                $icon = call_user_func($icon_callback);
260 28
                break;
261
            // configuration icon
262
            case (isset(self::$_cache['create_icon_map'][$type])):
263 28
                $icon = self::$_cache['create_icon_map'][$type];
264
                break;
265
266
            // heuristics magic (instead of adding something here, take a look at config key "create_type_magic")
267 28
            case (strpos($type, 'member') !== false):
268 16
            case (strpos($type, 'organization') !== false):
269 16
                $icon = 'users';
270
                break;
271
            case (strpos($type, 'person') !== false):
272 25
                $icon = 'user-o';
273 25
                break;
274 3
            case (strpos($type, 'event') !== false):
275 3
                $icon = 'calendar-o';
276 24
                break;
277 1
278 1
            // Fallback default value
279 23
            default:
280 1
                $icon = self::$_cache['create_icon_map']['__default__'];
281 1
                break;
282
        }
283
        return $icon;
284
    }
285 22
286 22
    /**
287
     * Get the object icon
288 28
     *
289
     * @param mixed $obj          MgdSchema object
290
     */
291
    public static function get_object_icon($obj) : string
292
    {
293
        if (null === self::$_cache['object_icon_map']) {
294
            self::$_cache['object_icon_map'] = self::_get_icon_map('object_icon_magic', 'file');
295
        }
296 12
297
        $object_class = get_class($obj);
298 12
        $object_baseclass = self::resolve_baseclass($obj);
299 1
300
        switch (true) {
301
            // object knows it's icon, how handy!
302 12
            case (method_exists($obj, 'get_icon')):
303 12
                $icon = $obj->get_icon();
304
                break;
305
306
            // configuration icon
307 12
            case (isset(self::$_cache['object_icon_map'][$object_class])):
308 4
                $icon = self::$_cache['object_icon_map'][$object_class];
309 4
                break;
310
            case (isset(self::$_cache['object_icon_map'][$object_baseclass])):
311
                $icon = self::$_cache['object_icon_map'][$object_baseclass];
312 9
                break;
313 2
314 2
            // heuristics magic (instead of adding something here, take a look at config key "object_icon_magic")
315 8
            case (strpos($object_class, 'person') !== false):
316 2
                $icon = 'user';
317 2
                break;
318
            case (strpos($object_class, 'event') !== false):
319
                $icon = 'calendar-o';
320 7
                break;
321 3
            case (strpos($object_class, 'member') !== false):
322 3
            case (strpos($object_class, 'organization') !== false):
323 6
            case (strpos($object_class, 'group') !== false):
324 1
                $icon = 'users';
325 1
                break;
326 5
            case (strpos($object_class, 'element') !== false):
327 5
                $icon = 'file-code-o';
328 4
                break;
329 3
330 3
            // Fallback default value
331 4
            default:
332 1
                $icon = self::$_cache['object_icon_map']['__default__'];
333 1
                break;
334
        }
335
336
        return '<i class="fa fa-' . $icon . '"></i>';
337 3
    }
338 3
339
    private static function _get_icon_map(string $config_key, string $fallback) : array
340
    {
341 12
        $config = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config');
342
        $icons2classes = $config->get($config_key);
343
        $icon_map = [];
344 2
        //sanity
345
        if (!is_array($icons2classes)) {
346 2
            throw new midcom_error('Config key "' . $config_key . '" is not an array');
347 2
        }
348 2
        foreach ($icons2classes as $icon => $classes) {
349
            $icon_map = array_merge($icon_map, array_fill_keys($classes, $icon));
350 2
        }
351
        if (!isset($icon_map['__default__'])) {
352
            $icon_map['__default__'] = $fallback;
353
        }
354 2
        return $icon_map;
355 2
    }
356
357
    /**
358 2
     * Get class properties to use as search fields in choosers or other direct DB searches
359
     */
360
    public function get_search_properties() : array
361 2
    {
362
        // Return cached results if we have them
363
        static $cache = [];
364
        if (isset($cache[$this->mgdschema_class])) {
365
            return $cache[$this->mgdschema_class];
366
        }
367 15
        debug_add("Starting analysis for class {$this->mgdschema_class}");
368
369
        $properties = self::get_object_fieldnames($this->_dummy_object);
370 15
371 15
        $default_properties = [
372 9
            'title' => true,
373
            'tag' => true,
374 7
            'firstname' => true,
375
            'lastname' => true,
376 7
            'official' => true,
377
            'username' => true,
378
        ];
379 7
380
        $search_properties = array_intersect_key($default_properties, array_flip($properties));
381
382
        foreach ($properties as $property) {
383
            if (strpos($property, 'name') !== false) {
384
                $search_properties[$property] = true;
385
            }
386
            // TODO: More per property heuristics
387 7
        }
388
        // TODO: parent and up heuristics
389 7
390 7
        $label_prop = $this->get_label_property();
391 6
392
        if (    is_string($label_prop)
393
             && $label_prop != 'guid'
394
             && $this->_mgd_reflector->property_exists($label_prop)) {
395
            $search_properties[$label_prop] = true;
396
        }
397 7
398
        // Exceptions - always search these fields
399 7
        $always_search_all = $this->_config->get('always_search_fields') ?: [];
400 7
        if (!empty($always_search_all[$this->mgdschema_class])) {
401 7
            $fields = array_intersect($always_search_all[$this->mgdschema_class], $properties);
402 6
            $search_properties += array_flip($fields);
403
        }
404
405
        // Exceptions - never search these fields
406 7
        $never_search_all = $this->_config->get('never_search_fields') ?: [];
407 7
        if (!empty($never_search_all[$this->mgdschema_class])) {
408 1
            $search_properties = array_diff_key($search_properties, array_flip($never_search_all[$this->mgdschema_class]));
409 1
        }
410
411
        $search_properties = array_keys($search_properties);
412
        debug_print_r("Search properties for {$this->mgdschema_class}: ", $search_properties);
413 7
        $cache[$this->mgdschema_class] = $search_properties;
414 7
        return $search_properties;
415
    }
416
417
    /**
418 7
     * Gets a list of link properties and the links target info
419 7
     *
420 7
     * Link info key specification
421 7
     *     'class' string link target class name
422
     *     'target' string link target property (of target class)
423
     *     'parent' boolean link is link to "parent" in object tree
424
     *     'up' boolean link is link to "up" in object tree
425
     *
426
     * @return array multidimensional array keyed by property, values are arrays with link info (or false in case of failure)
427
     */
428
    public function get_link_properties() : array
429
    {
430
        // Return cached results if we have them
431
        static $cache = [];
432
        if (isset($cache[$this->mgdschema_class])) {
433
            return $cache[$this->mgdschema_class];
434
        }
435 4
        debug_add("Starting analysis for class {$this->mgdschema_class}");
436
437
        // Shorthands
438 4
        $ref = $this->_mgd_reflector;
439 4
        $obj = $this->_dummy_object;
440 1
441
        // Get property list and start checking (or abort on error)
442 3
        $properties = self::get_object_fieldnames($obj);
443
444
        $links = [];
445 3
        $parent_property = midgard_object_class::get_property_parent($obj);
446 3
        $up_property = midgard_object_class::get_property_up($obj);
447
        foreach ($properties as $property) {
448
            if ($property == 'guid') {
449 3
                // GUID, even though of type MGD_TYPE_GUID, is never a link
450
                continue;
451 3
            }
452 3
453 3
            if (   !$ref->is_link($property)
454 3
                && $ref->get_midgard_type($property) != MGD_TYPE_GUID) {
455 3
                continue;
456
            }
457 3
            debug_add("Processing property '{$property}'");
458
            $linkinfo = [
459
                'class' => null,
460 3
                'target' => null,
461 3
                'parent' => false,
462 3
                'up' => false,
463
                'type' => $ref->get_midgard_type($property),
464 3
            ];
465
            if ($parent_property === $property) {
466 3
                debug_add("Is 'parent' property");
467
                $linkinfo['parent'] = true;
468
            }
469
            if ($up_property === $property) {
470 3
                debug_add("Is 'up' property");
471
                $linkinfo['up'] = true;
472 3
            }
473 2
474 2
            $type = $ref->get_link_name($property);
475
            debug_add("get_link_name returned '{$type}'");
476 3
            if (!empty($type)) {
477 1
                $linkinfo['class'] = $type;
478 1
            }
479
480
            $target = $ref->get_link_target($property);
481 3
482 3
            debug_add("get_link_target returned '{$target}'");
483 3
            if (!empty($target)) {
484 2
                $linkinfo['target'] = $target;
485
            } elseif ($linkinfo['type'] == MGD_TYPE_GUID) {
486
                $linkinfo['target'] = 'guid';
487 3
            }
488
489 3
            $links[$property] = $linkinfo;
490 3
        }
491 2
492 1
        debug_print_r("Links for {$this->mgdschema_class}: ", $links);
493 1
        $cache[$this->mgdschema_class] = $links;
494
        return $links;
495
    }
496 3
497
    /**
498
     * Map extended classes
499 3
     *
500 3
     * For example org.openpsa.* components often expand core objects,
501 3
     * in config we specify which classes we wish to substitute with which
502
     *
503
     * @param string $schema_type classname to check rewriting for
504
     * @return string new classname (or original in case no rewriting is to be done)
505
     */
506
    public static function class_rewrite(string $schema_type) : string
507
    {
508
        static $extends = false;
509
        if ($extends === false) {
510
            $extends = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('class_extends');
511
            // Safety against misconfiguration
512
            if (!is_array($extends)) {
513 38
                throw new midcom_error("config->get('class_extends') did not return array, invalid configuration ??");
514
            }
515 38
        }
516 38
        if (   isset($extends[$schema_type])
517
            && class_exists($extends[$schema_type])) {
518
            return $extends[$schema_type];
519
        }
520
        return $schema_type;
521
    }
522
523
    /**
524 38
     * See if two MgdSchema classes are the same
525 38
     *
526 2
     * NOTE: also takes into account the various extended class scenarios
527
     *
528 37
     * @param string $class_one first class to compare
529
     * @param string $class_two second class to compare
530
     */
531
    public static function is_same_class($class_one, $class_two) : bool
532
    {
533
        $one = self::resolve_baseclass($class_one);
534
        $two = self::resolve_baseclass($class_two);
535
        return $one == $two;
536
    }
537
538
    /**
539 12
     * Get the MgdSchema classname for given class
540
     *
541 12
     * @param mixed $classname either string (class name) or object
542 12
     * @return string the base class name
543 12
     */
544
    public static function resolve_baseclass($classname) : ?string
545
    {
546
        static $cached = [];
547
548
        if (is_object($classname)) {
549
            $class_instance = $classname;
550
            $classname = get_class($classname);
551
        }
552 225
553
        if (empty($classname)) {
554 225
            return null;
555
        }
556 225
557 182
        if (isset($cached[$classname])) {
558 182
            return $cached[$classname];
559
        }
560
561 225
        if (!isset($class_instance)) {
562
            $class_instance = new $classname();
563
        }
564
565 225
        // Check for decorators first
566 205
        if (!empty($class_instance->__mgdschema_class_name__)) {
567
            $parent_class = $class_instance->__mgdschema_class_name__;
568
            if (   !empty($class_instance->__object)
569 36
                && !$class_instance->__object instanceof $class_instance->__mgdschema_class_name__) {
570 9
                $parent_class = get_class($class_instance->__object);
571
                debug_add('mgdschema object class ' . $parent_class . ' is not an instance of ' . $class_instance->__mgdschema_class_name__, MIDCOM_LOG_INFO);
572
            }
573
        } else {
574 36
            $parent_class = $classname;
575 30
        }
576 30
577 30
        $cached[$classname] = self::class_rewrite($parent_class);
578
579 30
        return $cached[$classname];
580
    }
581
582 7
    /**
583
     * Resolve the "name" property of given object
584
     *
585 36
     * @see midcom_helper_reflector::get_name_property()
586
     * @param object $object the object to get the name property for
587 36
     * @return string name of property or boolean false on failure
588
     * @todo when midgard_reflection_property supports flagging name fields use that instead of heuristics
589
     */
590
    public function get_name_property_nonstatic($object)
591
    {
592
        return $this->get_property('name', $object);
593
    }
594
595
    private function get_property(string $type, $object)
596
    {
597
        // Cache results per class within request
598 37
        $key = get_class($object);
599
        if (isset(self::$_cache[$type][$key])) {
600
            return self::$_cache[$type][$key];
601 37
        }
602 37
        self::$_cache[$type][$key] = false;
603 6
604
        // Configured properties
605 33
        $exceptions = $this->_config->get($type . '_exceptions');
606
        foreach ($exceptions as $class => $property) {
607
            if (midcom::get()->dbfactory->is_a($object, $class)) {
608 33
                if (   $property !== false
609 33
                    && !$this->_mgd_reflector->property_exists($property)) {
610 33
                    debug_add("Matched class '{$key}' to '{$class}' via is_a but property '{$property}' does not exist", MIDCOM_LOG_ERROR);
611 2
                } else {
612 2
                    self::$_cache[$type][$key] = $property;
613
                }
614
                return self::$_cache[$type][$key];
615
            }
616
        }
617 2
        // The simple heuristic
618 2
        if ($this->_mgd_reflector->property_exists($type)) {
619
            self::$_cache[$type][$key] = $type;
620
        }
621
        return self::$_cache[$type][$key];
622
    }
623 32
624 9
    /**
625
     * Resolve the "name" property of given object
626 32
     *
627
     * @see midcom_helper_reflector::get_name_property_nonstatic()
628
     * @param object $object the object to get the name property for
629
     * @return string name of property or boolean false on failure
630
     */
631
    public static function get_name_property($object)
632
    {
633
        return self::get($object)->get_name_property_nonstatic($object);
634
    }
635
636 297
    /**
637
     * Resolve the "title" of given object
638
     *
639 297
     * NOTE: This is distinctly different from get_object_label, which will always return something
640 297
     * even if it's just the class name and GUID, also it will for some classes include extra info (like datetimes)
641
     * which we do not want here.
642 31
     *
643
     * @param object $object the object to get the name property for
644
     * @param string $title_property property to use as "name", if left to default (null), will be reflected
645
     * @return string value of name property or boolean false on failure
646
     */
647
    public static function get_object_title($object, $title_property = null)
648 297
    {
649
        if ($title_property === null) {
650
            $title_property = self::get_title_property($object);
651
        }
652
        if (empty($title_property)) {
653
            // Could not resolve valid property
654
            return false;
655
        }
656
657
        return (string) $object->{$title_property};
658
    }
659
660
    /**
661
     * Resolve the "title" property of given object
662 180
     *
663
     * NOTE: This is distinctly different from get_label_property, which will always return something
664 180
     * even if it's just the guid
665 180
     *
666
     * @param object $object The object to get the title property for
667 180
     * @return string Name of property or boolean false on failure
668 180
     */
669
    public static function get_title_property($object)
670 3
    {
671
        return self::get($object)->get_title_property_nonstatic($object);
672
    }
673 177
674
    /**
675
     * Resolve the "title" property of given object
676
     *
677
     * NOTE: This is distinctly different from get_label_property, which will always return something
678
     * even if it's just the guid
679
     *
680
     * @see midcom_helper_reflector::get_object_title()
681
     * @param object $object the object to get the title property for
682
     * @return string name of property or boolean false on failure
683
     */
684
    public function get_title_property_nonstatic($object)
685 202
    {
686
        return $this->get_property('title', $object);
687 202
    }
688
}
689