10000 bug #9885 [Dependencyinjection] Fixed handling of inlined references … · symfony/symfony@c63bbe9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c63bbe9

Browse files
committed
bug #9885 [Dependencyinjection] Fixed handling of inlined references 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)
2 parents 7fc0a53 + d650295 commit c63bbe9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
125125
return true;
126126
}
127127

128+
if ($this->currentId == $id) {
129+
return false;
130+
}
131+
128132
$ids = array();
129133
foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
130134
$ids[] = $edge->getSourceNode()->getId();

src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
144144
$this->assertSame($ref, $arguments[0]);
145145
}
146146

147+
public function testProcessDoesNotInlineWhenServiceReferencesItself()
148+
{
149+
$container = new ContainerBuilder();
150+
$container
151+
->register('foo')
152+
->setPublic(false)
153+
->addMethodCall('foo', array($ref = new Reference('foo')))
154+
;
155+
156+
$this->process($container);
157+
158+
$calls = $container->getDefinition('foo')->getMethodCalls();
159+
$this->assertSame($ref, $calls[0][1][0]);
160+
}
161+
147162
protected function process(ContainerBuilder $container)
148163
{
149164
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));

0 commit comments

Comments
 (0)
0