Permalink
Browse files

[DependencyInjection] fixed a non-detected circular reference in PhpD…

…umper (closes #8425)

This circular reference cannot be detected by the compiler pass as we
don't check for method arguments there.

The Container itself already detects such circular references at runtime.

So this fix is about circular references that are not detected at
compile time, and are not even detected at runtime because the code that
would cause the detection is never run (generated after a return
statement.)
  • Loading branch information...
1 parent 6ec2cba commit ce7de37f1623f7edde972cdbc7ad3c4d733e7bae @fabpot fabpot committed Sep 12, 2013
@@ -387,6 +387,12 @@ private function addServiceInlinedDefinitionsSetup($id, $definition)
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);
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
$code .= $this->addServiceProperties(null, $iDefinition, $name);
@@ -155,4 +155,19 @@ public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFrom
$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();
+ }
}

0 comments on commit ce7de37

Please sign in to comment.