@@ 149-165 (lines=17) @@ | ||
146 | * |
|
147 | * @throws \InvalidArgumentException |
|
148 | */ |
|
149 | protected static function getReflectionClassWithConstant($class, $constantName) |
|
150 | { |
|
151 | Assert::string($class, 'First argument to Reflection::getReflectionClassWithConstant must be string. Variable of type "%s" was given.'); |
|
152 | Assert::classExists($class, 'Could not find class "%s"'); |
|
153 | ||
154 | $refl = new \ReflectionClass($class); |
|
155 | if ($refl->hasConstant($constantName)) { |
|
156 | return $refl; |
|
157 | } |
|
158 | ||
159 | if (false === $parent = get_parent_class($class)) { |
|
160 | // No more parents |
|
161 | return null; |
|
162 | } |
|
163 | ||
164 | return self::getReflectionClassWithConstant($parent, $constantName); |
|
165 | } |
|
166 | ||
167 | /** |
|
168 | * Get a reflection class that has this property. |
|
@@ 177-193 (lines=17) @@ | ||
174 | * |
|
175 | * @throws \InvalidArgumentException |
|
176 | */ |
|
177 | protected static function getReflectionClassWithProperty($class, $propertyName) |
|
178 | { |
|
179 | Assert::string($class, 'First argument to Reflection::getReflectionClassWithProperty must be string. Variable of type "%s" was given.'); |
|
180 | Assert::classExists($class, 'Could not find class "%s"'); |
|
181 | ||
182 | $refl = new \ReflectionClass($class); |
|
183 | if ($refl->hasProperty($propertyName)) { |
|
184 | return $refl; |
|
185 | } |
|
186 | ||
187 | if (false === $parent = get_parent_class($class)) { |
|
188 | // No more parents |
|
189 | return null; |
|
190 | } |
|
191 | ||
192 | return self::getReflectionClassWithProperty($parent, $propertyName); |
|
193 | } |
|
194 | ||
195 | /** |
|
196 | * Get an reflection property that you can access directly. |