Completed
Push — master ( 2134f6...01c567 )
by Andreas
22:35
created

midcom_helper_reflector::class_rewrite()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675

Importance

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