diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 63b8d79a853f..d8d08cd52e1b 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -93,8 +93,6 @@ public function __construct(ParameterBagInterface $parameterBag = null) $this->scopeChildren = array(); $this->scopedServices = array(); $this->scopeStacks = array(); - - $this->set('service_container', $this); } /** @@ -204,6 +202,12 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) $id = strtolower($id); + if ('service_container' === $id) { + // BC: 'service_container' is no longer a self-reference but always + // $this, so ignore this call. + // @todo Throw InvalidArgumentException in next major release. + return; + } if (self::SCOPE_CONTAINER !== $scope) { if (!isset($this->scopedServices[$scope])) { throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id)); @@ -240,6 +244,10 @@ public function has($id) { $id = strtolower($id); + if ('service_container' === $id) { + return true; + } + return isset($this->services[$id]) || array_key_exists($id, $this->services) || isset($this->aliases[$id]) @@ -276,6 +284,9 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE if ($strtolower) { $id = strtolower($id); } + if ('service_container' === $id) { + return $this; + } if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } @@ -347,6 +358,12 @@ public function initialized($id) { $id = strtolower($id); + if ('service_container' === $id) { + // BC: 'service_container' was a synthetic service previously. + // @todo Change to false in next major release. + return true; + } + return isset($this->services[$id]) || array_key_exists($id, $this->services); } @@ -364,6 +381,7 @@ public function getServiceIds() $ids[] = self::underscore($match[1]); } } + $ids[] = 'service_container'; return array_unique(array_merge($ids, array_keys($this->services))); }