8000 bug #25203 [DI] Fix infinite loop in InlineServiceDefinitionsPass (ni… · symfony/symfony@85223d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85223d3

Browse files
bug #25203 [DI] Fix infinite loop in InlineServiceDefinitionsPass (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [DI] Fix infinite loop in InlineServiceDefinitionsPass | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - When a non-shared is involved in a setter-circular loop, the pass enters an infinite loop right now. Commits ------- b988aa7 [DI] Fix infinite loop in InlineServiceDefinitionsPass
2 parents 020d78a + b988aa7 commit 85223d3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ protected function processValue($value, $isRoot = false)
6161
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
6262
$this->inlinedServiceIds[$id][] = $this->currentId;
6363

64-
if ($definition->isShared()) {
65-
return $definition;
66-
}
67-
$value = clone $definition;
64+
return $definition->isShared() ? $definition : clone $definition;
6865
}
6966
}
7067

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public function testProcessDoesInlineNonSharedService()
9292
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
9393
}
9494

95+
public function testProcessInlinesMixedServicesLoop()
96+
{
97+
$container = new ContainerBuilder();
98+
$container
99+
->register('foo')
100+
->addArgument(new Reference('bar'))
101+
->setShared(false)
102+
;
103+
$container
104+
->register('bar')
105+
->setPublic(false)
106+
->addMethodCall('setFoo', array(new Reference('foo')))
107+
;
108+
109+
$this->process($container);
110+
111+
$this->assertEquals($container->getDefinition('foo')->getArgument(0), $container->getDefinition('bar'));
112+
}
113+
95114
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
96115
{
97116
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0