Completed
Push — master ( d0f0fb...030685 )
by Andreas
23:49
created

midcom_helper_reflector::get_object_fieldnames()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.009

Importance

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