Skip to content

Commit

Permalink
[DependencyInjection] Removed extra strtolower calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dosten authored and fabpot committed Apr 27, 2015
1 parent 5206603 commit 3bfbf45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -470,7 +470,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
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]);
}

Expand Down Expand Up @@ -686,7 +686,7 @@ public function setAlias($alias, $id)
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));
}

Expand Down Expand Up @@ -748,7 +748,7 @@ public function getAlias($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));
}

Expand Down Expand Up @@ -866,7 +866,7 @@ public function getDefinition($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));
}

Expand All @@ -888,8 +888,10 @@ public function getDefinition($id)
*/
public function findDefinition($id)
{
while ($this->hasAlias($id)) {
$id = (string) $this->getAlias($id);
$id = strtolower($id);

while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];
}

return $this->getDefinition($id);
Expand Down
Expand Up @@ -189,6 +189,13 @@ public function testAliases()
$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');

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 {
$builder->getAlias('foobar');
$this->fail('->getAlias() throws an InvalidArgumentException if the alias does not exist');
Expand Down

0 comments on commit 3bfbf45

Please sign in to comment.