Skip to content

Commit

Permalink
bug #9885 [Dependencyinjection] Fixed handling of inlined references …
Browse files Browse the repository at this point in the history
…in the AnalyzeServiceReferencesPass (fabpot)

This PR was merged into the 2.3 branch.

Discussion
----------

[Dependencyinjection] Fixed handling of inlined references in the AnalyzeServiceReferencesPass

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8299, #9829
| License       | MIT
| Doc PR        | n/a

Hopefully a better fix for #9829 (ping @jakzal). Unit tests coming soon.

In some cases `InlineServiceDefinitionsPass` replaces a Reference with a service Definition. In such scenarios `AnalyzeServiceReferencesPass` was falling into an infinite loop.

Commits
-------

d650295 [DependencyInjection] fixed InlineServiceDefinitionsPass to not inline a service if it's part of the current definition (to avoid an infinite loop)
  • Loading branch information
fabpot committed Dec 29, 2013
2 parents 7fc0a53 + d650295 commit c63bbe9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -125,6 +125,10 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
return true;
}

if ($this->currentId == $id) {
return false;
}

$ids = array();
foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
$ids[] = $edge->getSourceNode()->getId();
Expand Down
Expand Up @@ -144,6 +144,21 @@ public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
$this->assertSame($ref, $arguments[0]);
}

public function testProcessDoesNotInlineWhenServiceReferencesItself()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
->addMethodCall('foo', array($ref = new Reference('foo')))
;

$this->process($container);

$calls = $container->getDefinition('foo')->getMethodCalls();
$this->assertSame($ref, $calls[0][1][0]);
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
Expand Down

0 comments on commit c63bbe9

Please sign in to comment.