From 9922827cc2eb15f41823df30e7fa3b7cf891a512 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 17 Jul 2017 22:28:29 +0200 Subject: [PATCH] [DI] Resolve aliases earlier --- .../Component/DependencyInjection/Container.php | 14 +++++++------- .../DependencyInjection/Dumper/PhpDumper.php | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 7bf2e36ec2..4019504a5a 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -249,9 +249,6 @@ class Container implements IntrospectableContainerInterface // this method can be called thousands of times during a request, avoid // calling strtolower() unless necessary. for ($i = 2;;) { - if ('service_container' === $id) { - return $this; - } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } @@ -259,6 +256,9 @@ class Container implements IntrospectableContainerInterface if (isset($this->services[$id]) || array_key_exists($id, $this->services)) { return $this->services[$id]; } + if ('service_container' === $id) { + return $this; + } if (isset($this->loading[$id])) { throw new ServiceCircularReferenceException($id, array_keys($this->loading)); @@ -328,16 +328,16 @@ class Container implements IntrospectableContainerInterface { $id = strtolower($id); + if (isset($this->aliases[$id])) { + $id = $this->aliases[$id]; + } + if ('service_container' === $id) { // BC: 'service_container' was a synthetic service previously. // @todo Change to false in next major release. return true; } - if (isset($this->aliases[$id])) { - $id = $this->aliases[$id]; - } - return isset($this->services[$id]) || array_key_exists($id, $this->services); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 1665f7542b..52f6362c73 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1482,6 +1482,10 @@ EOF; */ private function getServiceCall($id, Reference $reference = null) { + while ($this->container->hasAlias($id)) { + $id = (string) $this->container->getAlias($id); + } + if ('service_container' === $id) { return '$this'; } @@ -1490,10 +1494,6 @@ EOF; return sprintf('$this->get(\'%s\', ContainerInterface::NULL_ON_INVALID_REFERENCE)', $id); } - if ($this->container->hasAlias($id)) { - $id = (string) $this->container->getAlias($id); - } - return sprintf('$this->get(\'%s\')', $id); }