minor #14470 [DependencyInjection] Removed extra strtolower calls (dosten)
This PR was squashed before being merged into the 2.3 branch (closes #14470).
Discussion
----------
[DependencyInjection] Removed extra strtolower calls
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
`Alias` already lowercase the `$id` in the constructor. Using `ContainerBuilder::hasAlias()` and `ContainerBuilder::hasDefinition()` inside the code makes an extra strtolower call.
Commits
-------
3bfbf45
[DependencyInjection] Removed extra strtolower calls
This commit is contained in:
commit
8f7a55864a
|
@ -470,7 +470,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||
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]);
|
||||
}
|
||||
|
||||
|
@ -686,7 +686,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||
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));
|
||||
}
|
||||
|
||||
|
@ -748,7 +748,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||
{
|
||||
$id = strtolower($id);
|
||||
|
||||
if (!$this->hasAlias($id)) {
|
||||
if (!isset($this->aliasDefinitions[$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);
|
||||
|
||||
if (!$this->hasDefinition($id)) {
|
||||
if (!array_key_exists($id, $this->definitions)) {
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -189,6 +189,13 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
$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');
|
||||
|
|
Reference in New Issue