Skip to content

[DependencyInjection] Removed extra strtolower calls #14470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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