1: <?php
2:
3: namespace TIC\CoreBundle\Util;
4:
5: class ClassHelper
6: {
7: /**
8: * This class should not be instantiated.
9: */
10: private function __construct()
11: {
12: }
13:
14: public static function hasTrait($object, $nameTrait): bool
15: {
16:
17: $todo = [];
18: $done = [];
19:
20: do {
21: $todo += class_uses($object);
22:
23: while (!empty($todo)) {
24: $trait = array_pop($todo);
25: if (in_array($trait, $done)) continue;
26:
27: if ($trait == $nameTrait) return true;
28:
29: $todo += class_uses($trait);
30:
31: $done[] = $trait;
32: }
33:
34: } while($object = get_parent_class($object));
35:
36: return false;
37: }
38: }
39: