[DependencyInjection] Removed extra strtolower calls

This commit is contained in:
Diego Saint Esteben 2015-04-25 13:37:49 -03:00 committed by Fabien Potencier
parent 520660302a
commit 3bfbf45ed2
2 changed files with 15 additions and 6 deletions

View File

@ -470,7 +470,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id)); throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id));
} }
if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) { if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
return $this->get($this->aliasDefinitions[$id]); return $this->get($this->aliasDefinitions[$id]);
} }
@ -686,7 +686,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
throw new InvalidArgumentException('$id must be a string, or an Alias object.'); throw new InvalidArgumentException('$id must be a string, or an Alias object.');
} }
if ($alias === strtolower($id)) { if ($alias === (string) $id) {
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias)); throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
} }
@ -748,7 +748,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
{ {
$id = strtolower($id); $id = strtolower($id);
if (!$this->hasAlias($id)) { if (!isset($this->aliasDefinitions[$id])) {
throw new InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id)); throw new InvalidArgumentException(sprintf('The service alias "%s" does not exist.', $id));
} }
@ -866,7 +866,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
{ {
$id = strtolower($id); $id = strtolower($id);
if (!$this->hasDefinition($id)) { if (!array_key_exists($id, $this->definitions)) {
throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id)); throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
} }
@ -888,8 +888,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/ */
public function findDefinition($id) public function findDefinition($id)
{ {
while ($this->hasAlias($id)) { $id = strtolower($id);
$id = (string) $this->getAlias($id);
while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];
} }
return $this->getDefinition($id); return $this->getDefinition($id);

View File

@ -189,6 +189,13 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($builder->has('bar'), '->setAlias() defines a new service'); $this->assertTrue($builder->has('bar'), '->setAlias() defines a new service');
$this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one'); $this->assertTrue($builder->get('bar') === $builder->get('foo'), '->setAlias() creates a service that is an alias to another one');
try {
$builder->setAlias('foobar', 'foobar');
$this->fail('->setAlias() throws an InvalidArgumentException if the alias references itself');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('An alias can not reference itself, got a circular reference on "foobar".', $e->getMessage(), '->setAlias() throws an InvalidArgumentException if the alias references itself');
}
try { try {
$builder->getAlias('foobar'); $builder->getAlias('foobar');
$this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist'); $this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');