Skip to content

Commit

Permalink
Avoid levenshtein comparison when using ContainerBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
catch authored and fabpot committed Mar 27, 2014
1 parent ea4b8bf commit cc9cc37
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -461,52 +461,44 @@ public function has($id)
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]);
}
$this->loading[$id] = true;

try {
$definition = $this->getDefinition($id);
} catch (InvalidArgumentException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}
try {
$service = $this->createService($definition, $id);
} catch (\Exception $e) {
unset($this->loading[$id]);

throw $e;
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}

$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;
}
throw $e;
}

unset($this->loading[$id]);
unset($this->loading[$id]);

return $service;
}
return $service;
}

/**
Expand Down

0 comments on commit cc9cc37

Please sign in to comment.