Break infinite loop while resolving aliases
This commit is contained in:
parent
6a62318894
commit
acbde502bf
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
|
@ -84,7 +85,12 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
|
|||
*/
|
||||
private function getDefinitionId($id)
|
||||
{
|
||||
$seen = array();
|
||||
while ($this->container->hasAlias($id)) {
|
||||
if (isset($seen[$id])) {
|
||||
throw new ServiceCircularReferenceException($id, array_keys($seen));
|
||||
}
|
||||
$seen[$id] = true;
|
||||
$id = (string) $this->container->getAlias($id);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,17 @@ class ResolveReferencesToAliasesPassTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('foo', (string) $arguments[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||
*/
|
||||
public function testAliasCircularReference()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setAlias('bar', 'foo');
|
||||
$container->setAlias('foo', 'bar');
|
||||
$this->process($container);
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveReferencesToAliasesPass();
|
||||
|
|
Reference in New Issue