From cc9cc37e790a4dd6fa05e2b1d9079215d59752b7 Mon Sep 17 00:00:00 2001 From: catch Date: Wed, 26 Mar 2014 14:45:08 +0100 Subject: [PATCH] Avoid levenshtein comparison when using ContainerBuilder. --- .../DependencyInjection/ContainerBuilder.php | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index dc5738a5cf..85ea49e67a 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -461,52 +461,44 @@ class ContainerBuilder extends Container implements TaggedContainerInterface public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { $id = strtolower($id); + if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) { + return $service; + } + if (isset($this->loading[$id])) { + throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e); + } + + if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) { + return $this->get($this->aliasDefinitions[$id]); + } try { - return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE); - } catch (InactiveScopeException $e) { + $definition = $this->getDefinition($id); + } catch (InvalidArgumentException $e) { if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { return null; } throw $e; - } catch (InvalidArgumentException $e) { - if (isset($this->loading[$id])) { - throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e); - } + } - if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) { - return $this->get($this->aliasDefinitions[$id]); - } - - try { - $definition = $this->getDefinition($id); - } catch (InvalidArgumentException $e) { - if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { - return null; - } - - throw $e; - } - - $this->loading[$id] = true; - - try { - $service = $this->createService($definition, $id); - } catch (\Exception $e) { - unset($this->loading[$id]); - - if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { - return null; - } - - throw $e; - } + $this->loading[$id] = true; + try { + $service = $this->createService($definition, $id); + } catch (\Exception $e) { unset($this->loading[$id]); - return $service; + if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) { + return null; + } + + throw $e; } + + unset($this->loading[$id]); + + return $service; } /**