minor #18021 Don't use reflections when possible (Ener-Getick)
This PR was merged into the 2.3 branch.
Discussion
----------
Don't use reflections when possible
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Use php functions instead of reflection when possible (to improve a bit the performance).
Commits
-------
a46270a
Don't use reflections when possible
This commit is contained in:
commit
53033617f7
@ -363,9 +363,8 @@ class Container implements IntrospectableContainerInterface
|
|||||||
public function getServiceIds()
|
public function getServiceIds()
|
||||||
{
|
{
|
||||||
$ids = array();
|
$ids = array();
|
||||||
$r = new \ReflectionClass($this);
|
foreach (get_class_methods($this) as $method) {
|
||||||
foreach ($r->getMethods() as $method) {
|
if (preg_match('/^get(.+)Service$/', $method, $match)) {
|
||||||
if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
|
|
||||||
$ids[] = self::underscore($match[1]);
|
$ids[] = self::underscore($match[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,11 @@ class GetSetDummy
|
|||||||
{
|
{
|
||||||
throw new \RuntimeException('Dummy::otherMethod() should not be called');
|
throw new \RuntimeException('Dummy::otherMethod() should not be called');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPrivate()
|
||||||
|
{
|
||||||
|
throw new \RuntimeException('Dummy::getPrivate() should not be called');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetConstructorDummy
|
class GetConstructorDummy
|
||||||
|
@ -45,12 +45,11 @@ class PropertyMetadata extends MemberMetadata
|
|||||||
*/
|
*/
|
||||||
protected function newReflectionMember($objectOrClassName)
|
protected function newReflectionMember($objectOrClassName)
|
||||||
{
|
{
|
||||||
$class = new \ReflectionClass($objectOrClassName);
|
while (!property_exists($objectOrClassName, $this->getName())) {
|
||||||
while (!$class->hasProperty($this->getName())) {
|
$objectOrClassName = get_parent_class($objectOrClassName);
|
||||||
$class = $class->getParentClass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$member = new \ReflectionProperty($class->getName(), $this->getName());
|
$member = new \ReflectionProperty($objectOrClassName, $this->getName());
|
||||||
$member->setAccessible(true);
|
$member->setAccessible(true);
|
||||||
|
|
||||||
return $member;
|
return $member;
|
||||||
|
Reference in New Issue
Block a user