Prevent a loop in aliases within the findDefinition
method
This commit is contained in:
parent
b783602622
commit
22f35239a4
@ -993,8 +993,15 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
{
|
{
|
||||||
$id = $this->normalizeId($id);
|
$id = $this->normalizeId($id);
|
||||||
|
|
||||||
|
$seen = array();
|
||||||
while (isset($this->aliasDefinitions[$id])) {
|
while (isset($this->aliasDefinitions[$id])) {
|
||||||
$id = (string) $this->aliasDefinitions[$id];
|
$id = (string) $this->aliasDefinitions[$id];
|
||||||
|
|
||||||
|
if (isset($seen[$id])) {
|
||||||
|
throw new ServiceCircularReferenceException($id, array_keys($seen));
|
||||||
|
}
|
||||||
|
|
||||||
|
$seen[$id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getDefinition($id);
|
return $this->getDefinition($id);
|
||||||
|
@ -1044,6 +1044,22 @@ class ContainerBuilderTest extends TestCase
|
|||||||
$this->assertNotSame($bar->foo, $barUser->foo);
|
$this->assertNotSame($bar->foo, $barUser->foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
|
* @expectedExceptionMessage Circular reference detected for service "app.test_class", path: "app.test_class -> App\TestClass".
|
||||||
|
*/
|
||||||
|
public function testThrowsCircularExceptionForCircularAliases()
|
||||||
|
{
|
||||||
|
$builder = new ContainerBuilder();
|
||||||
|
|
||||||
|
$builder->setAliases(array(
|
||||||
|
'app.test_class' => new Alias('App\\TestClass'),
|
||||||
|
'App\\TestClass' => new Alias('app.test_class'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$builder->findDefinition('App\\TestClass');
|
||||||
|
}
|
||||||
|
|
||||||
public function testInitializePropertiesBeforeMethodCalls()
|
public function testInitializePropertiesBeforeMethodCalls()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user