1 | <?php |
||
21 | class ReflectionClassConstant extends BaseReflectionClassConstant |
||
22 | { |
||
23 | use InternalPropertiesEmulationTrait; |
||
24 | |||
25 | /** |
||
26 | * Concrete class constant node |
||
27 | * |
||
28 | * @var ClassConst |
||
29 | */ |
||
30 | private $classConstantNode; |
||
31 | |||
32 | /** |
||
33 | * @var Const_ |
||
34 | */ |
||
35 | private $constNode; |
||
36 | |||
37 | /** |
||
38 | * Name of the class |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $className; |
||
43 | |||
44 | /** |
||
45 | * Parses class constants from the concrete class node |
||
46 | * |
||
47 | * @param ClassLike $classLikeNode Class-like node |
||
48 | * @param string $reflectionClassName FQN of the class |
||
49 | * |
||
50 | * @return array|ReflectionClassConstant[] |
||
51 | */ |
||
52 | 8 | public static function collectFromClassNode(ClassLike $classLikeNode, string $reflectionClassName): array |
|
53 | { |
||
54 | 8 | $classConstants = []; |
|
55 | |||
56 | 8 | foreach ($classLikeNode->stmts as $classLevelNode) { |
|
57 | 8 | if ($classLevelNode instanceof ClassConst) { |
|
58 | 7 | foreach ($classLevelNode->consts as $const) { |
|
59 | 7 | $classConstName = $const->name->toString(); |
|
60 | 7 | $classConstants[$classConstName] = new ReflectionClassConstant( |
|
61 | 7 | $reflectionClassName, |
|
62 | $classConstName, |
||
63 | $classLevelNode, |
||
64 | $const |
||
65 | ); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | 8 | return $classConstants; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Initializes a reflection for the class constant |
||
75 | * |
||
76 | * @param string $className Name of the class |
||
77 | * @param string $classConstantName Name of the class constant to reflect |
||
78 | * @param ClassConst $classConstNode ClassConstant definition node |
||
79 | * @param Const_|null $constNode Concrete const definition node |
||
80 | */ |
||
81 | 7 | public function __construct( |
|
98 | |||
99 | /** |
||
100 | * Emulating original behaviour of reflection |
||
101 | */ |
||
102 | 1 | public function ___debugInfo() |
|
109 | |||
110 | /** |
||
111 | * @inheritDoc |
||
112 | */ |
||
113 | 2 | public function getDeclaringClass() |
|
117 | |||
118 | /** |
||
119 | * @inheritDoc |
||
120 | */ |
||
121 | 1 | public function getDocComment() |
|
127 | |||
128 | /** |
||
129 | * @inheritDoc |
||
130 | */ |
||
131 | 2 | public function getModifiers() |
|
146 | |||
147 | /** |
||
148 | * @inheritDoc |
||
149 | */ |
||
150 | 4 | public function getName() |
|
154 | |||
155 | /** |
||
156 | * @inheritDoc |
||
157 | */ |
||
158 | 2 | public function getValue() |
|
164 | |||
165 | /** |
||
166 | * @inheritDoc |
||
167 | */ |
||
168 | 2 | public function isPrivate() |
|
172 | |||
173 | /** |
||
174 | * @inheritDoc |
||
175 | */ |
||
176 | 2 | public function isProtected() |
|
180 | |||
181 | /** |
||
182 | * @inheritDoc |
||
183 | */ |
||
184 | 2 | public function isPublic() |
|
188 | |||
189 | /** |
||
190 | * @inheritDoc |
||
191 | */ |
||
192 | 2 | public function __toString() |
|
215 | } |
||
216 |