diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index df62b22ff9d3..8e1c1a64ccb8 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -290,57 +290,60 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE if (isset($this->services[$id]) || array_key_exists($id, $this->services)) { return $this->services[$id]; } - } - if (isset($this->loading[$id])) { - throw new ServiceCircularReferenceException($id, array_keys($this->loading)); - } + if (isset($this->loading[$id])) { + throw new ServiceCircularReferenceException($id, array_keys($this->loading)); + } - if (isset($this->methodMap[$id])) { - $method = $this->methodMap[$id]; - } elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) { - // $method is set to the right value, proceed - } else { - if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { - if (!$id) { - throw new ServiceNotFoundException($id); - } + if (isset($this->methodMap[$id])) { + $method = $this->methodMap[$id]; + } elseif (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_', '\\' => '_')).'Service')) { + // $method is set to the right value, proceed + } else { + if ($strtolower && self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { + if (!$id) { + throw new ServiceNotFoundException($id); + } - $alternatives = array(); - foreach ($this->services as $key => $associatedService) { - $lev = levenshtein($id, $key); - if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) { - $alternatives[] = $key; + $alternatives = array(); + foreach ($this->services as $key => $associatedServices) { + $lev = levenshtein($id, $key); + if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) { + $alternatives[] = $key; + } } + + throw new ServiceNotFoundException($id, null, null, $alternatives); + } else if ($strtolower) { + return; + } else { + continue; } - throw new ServiceNotFoundException($id, null, null, $alternatives); } - return; - } + $this->loading[$id] = true; - $this->loading[$id] = true; + try { + $service = $this->$method(); + } catch (\Exception $e) { + unset($this->loading[$id]); - try { - $service = $this->$method(); - } catch (\Exception $e) { - unset($this->loading[$id]); + if (array_key_exists($id, $this->services)) { + unset($this->services[$id]); + } - if (array_key_exists($id, $this->services)) { - unset($this->services[$id]); - } + if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { + return; + } - if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { - return; + throw $e; } - throw $e; - } - - unset($this->loading[$id]); + unset($this->loading[$id]); - return $service; + return $service; + } } /**