8000 Don't use reflections when possible · symfony/symfony@a46270a · GitHub
[go: up one dir, main page]

Skip to content

Commit a46270a

Browse files
committed
Don't use reflections when possible
1 parent d791d78 commit a46270a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,8 @@ public function initialized($id)
363363
public function getServiceIds()
364364
{
365365
$ids = array();
366-
$r = new \ReflectionClass($this);
367-
foreach ($r->getMethods() as $method) {
368-
if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
366+
foreach (get_class_methods($this) as $method) {
367+
if (preg_match('/^get(.+)Service$/', $method, $match)) {
369368
$ids[] = self::underscore($match[1]);
370369
}
371370
}

src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ public function otherMethod()
298298
{
299299
throw new \RuntimeException('Dummy::otherMethod() should not be called');
300300
}
301+
302+
protected function getPrivate()
303+
{
304+
throw new \RuntimeException('Dummy::getPrivate() should not be called');
305+
}
301306
}
302307

303308
class GetConstructorDummy

src/Symfony/Component/Validator/Mapping/PropertyMetadata.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public function getPropertyValue($object)
4545
*/
4646
protected function newReflectionMember($objectOrClassName)
4747
{
48-
$class = new \ReflectionClass($objectOrClassName);
49-
while (!$class->hasProperty($this->getName())) {
50-
$class = $class->getParentClass();
48+
while (!property_exists($objectOrClassName, $this->getName())) {
49+
$objectOrClassName = get_parent_class($objectOrClassName);
5150
}
5251

53-
$member = new \ReflectionProperty($class->getName(), $this->getName());
52+
$member = new \ReflectionProperty($objectOrClassName, $this->getName());
5453
$member->setAccessible(true);
5554

5655
return $member;

0 commit comments

Comments
 (0)
0