merged branch fabpot/circular-refs-php-dumper (PR #8999)
This PR was merged into the 2.2 branch.
Discussion
----------
[DependencyInjection] fixed a non-detected circular reference in PhpDumper (closes #8425)
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #8425
| License | MIT
| Doc PR | n/a
Commits
-------
ce7de37
[DependencyInjection] fixed a non-detected circular reference in PhpDumper (closes #8425)
This commit is contained in:
commit
8aec247dc3
@ -387,6 +387,12 @@ class PhpDumper extends Dumper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the instance is simple, the return statement has already been generated
|
||||||
|
// so, the only possible way to get there is because of a circular reference
|
||||||
|
if ($this->isSimpleInstance($id, $definition)) {
|
||||||
|
throw new ServiceCircularReferenceException($id, array($id));
|
||||||
|
}
|
||||||
|
|
||||||
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
|
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
|
||||||
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
|
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
|
||||||
$code .= $this->addServiceProperties(null, $iDefinition, $name);
|
$code .= $this->addServiceProperties(null, $iDefinition, $name);
|
||||||
|
@ -155,4 +155,19 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
|
$this->assertSame($bar, $container->get('foo')->bar, '->set() overrides an already defined service');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
|
||||||
|
*/
|
||||||
|
public function testCircularReference()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$container->register('foo', 'stdClass')->addArgument(new Reference('bar'));
|
||||||
|
$container->register('bar', 'stdClass')->setPublic(false)->addMethodCall('setA', array(new Reference('baz')));
|
||||||
|
$container->register('baz', 'stdClass')->addMethodCall('setA', array(new Reference('foo')));
|
||||||
|
$container->compile();
|
||||||
|
|
||||||
|
$dumper = new PhpDumper($container);
|
||||||
|
$dumper->dump();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user