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()
|
||||
{
|
||||
$ids = array();
|
||||
$r = new \ReflectionClass($this);
|
||||
foreach ($r->getMethods() as $method) {
|
||||
if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
|
||||
foreach (get_class_methods($this) as $method) {
|
||||
if (preg_match('/^get(.+)Service$/', $method, $match)) {
|
||||
$ids[] = self::underscore($match[1]);
|
||||
}
|
||||
}
|
||||
|
@ -298,6 +298,11 @@ class GetSetDummy
|
||||
{
|
||||
throw new \RuntimeException('Dummy::otherMethod() should not be called');
|
||||
}
|
||||
|
||||
protected function getPrivate()
|
||||
{
|
||||
throw new \RuntimeException('Dummy::getPrivate() should not be called');
|
||||
}
|
||||
}
|
||||
|
||||
class GetConstructorDummy
|
||||
|
@ -45,12 +45,11 @@ class PropertyMetadata extends MemberMetadata
|
||||
*/
|
||||
protected function newReflectionMember($objectOrClassName)
|
||||
{
|
||||
$class = new \ReflectionClass($objectOrClassName);
|
||||
while (!$class->hasProperty($this->getName())) {
|
||||
$class = $class->getParentClass();
|
||||
while (!property_exists($objectOrClassName, $this->getName())) {
|
||||
$objectOrClassName = get_parent_class($objectOrClassName);
|
||||
}
|
||||
|
||||
$member = new \ReflectionProperty($class->getName(), $this->getName());
|
||||
$member = new \ReflectionProperty($objectOrClassName, $this->getName());
|
||||
$member->setAccessible(true);
|
||||
|
||||
return $member;
|
||||
|
Reference in New Issue
Block a user