1 | <?php |
||
25 | class ReflectionClass extends InternalReflectionClass |
||
26 | { |
||
27 | use ReflectionClassLikeTrait, InternalPropertiesEmulationTrait; |
||
28 | |||
29 | /** |
||
30 | * Initializes reflection instance |
||
31 | * |
||
32 | * @param string|object $argument Class name or instance of object |
||
33 | * @param ClassLike $classLikeNode AST node for class |
||
34 | */ |
||
35 | 108 | public function __construct($argument, ClassLike $classLikeNode = null) |
|
36 | { |
||
37 | 108 | $fullClassName = is_object($argument) ? get_class($argument) : $argument; |
|
38 | 108 | $namespaceParts = explode('\\', $fullClassName); |
|
39 | 108 | $this->className = array_pop($namespaceParts); |
|
40 | // Let's unset original read-only property to have a control over it via __get |
||
41 | 108 | unset($this->name); |
|
42 | |||
43 | 108 | $this->namespaceName = join('\\', $namespaceParts); |
|
44 | |||
45 | 108 | $this->classLikeNode = $classLikeNode ?: ReflectionEngine::parseClass($fullClassName); |
|
46 | 108 | } |
|
47 | |||
48 | /** |
||
49 | * Parses interfaces from the concrete class node |
||
50 | * |
||
51 | * @param ClassLike $classLikeNode Class-like node |
||
52 | * |
||
53 | * @return array|\ReflectionClass[] List of reflections of interfaces |
||
54 | */ |
||
55 | 96 | public static function collectInterfacesFromClassNode(ClassLike $classLikeNode) |
|
56 | { |
||
57 | 96 | $interfaces = []; |
|
58 | |||
59 | 96 | $isInterface = $classLikeNode instanceof Interface_; |
|
60 | 96 | $interfaceField = $isInterface ? 'extends' : 'implements'; |
|
61 | 96 | $hasInterfaces = in_array($interfaceField, $classLikeNode->getSubNodeNames()); |
|
62 | 96 | $implementsList = $hasInterfaces ? $classLikeNode->$interfaceField : array(); |
|
63 | 96 | if ($implementsList) { |
|
64 | 8 | foreach ($implementsList as $implementNode) { |
|
65 | 8 | if ($implementNode instanceof FullyQualified) { |
|
66 | 8 | $implementName = $implementNode->toString(); |
|
67 | 8 | $interface = interface_exists($implementName, false) |
|
68 | 8 | ? new parent($implementName) |
|
69 | 8 | : new static($implementName); |
|
70 | 8 | $interfaces[$implementName] = $interface; |
|
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | 96 | return $interfaces; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Parses traits from the concrete class node |
||
80 | * |
||
81 | * @param ClassLike $classLikeNode Class-like node |
||
82 | * @param array $traitAdaptations List of method adaptations |
||
83 | * |
||
84 | * @return array|\ReflectionClass[] List of reflections of traits |
||
85 | */ |
||
86 | 96 | public static function collectTraitsFromClassNode(ClassLike $classLikeNode, array &$traitAdaptations) |
|
87 | { |
||
88 | 96 | $traits = []; |
|
89 | |||
90 | 96 | if (!empty($classLikeNode->stmts)) { |
|
91 | 80 | foreach ($classLikeNode->stmts as $classLevelNode) { |
|
92 | 80 | if ($classLevelNode instanceof TraitUse) { |
|
93 | 14 | foreach ($classLevelNode->traits as $classTraitName) { |
|
94 | 14 | if ($classTraitName instanceof FullyQualified) { |
|
95 | 14 | $traitName = $classTraitName->toString(); |
|
96 | 14 | $trait = trait_exists($traitName, false) |
|
97 | 14 | ? new parent($traitName) |
|
98 | 14 | : new static($traitName); |
|
99 | 14 | $traits[$traitName] = $trait; |
|
100 | } |
||
101 | } |
||
102 | 80 | $traitAdaptations = $classLevelNode->adaptations; |
|
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | 96 | return $traits; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * Emulating original behaviour of reflection |
||
112 | */ |
||
113 | 1 | public function ___debugInfo() |
|
114 | { |
||
115 | return array( |
||
116 | 1 | 'name' => $this->getName() |
|
117 | ); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Implementation of internal reflection initialization |
||
122 | * |
||
123 | * @return void |
||
124 | */ |
||
125 | 4 | protected function __initialize() |
|
129 | } |
||
130 |