Skip to content

Commit c3f17ac

Browse files
bug #48931 [DependencyInjection] Fix dumping inlined withers (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Fix dumping inlined withers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48814 | License | MIT | Doc PR | - Commits ------- 455ace0 [DependencyInjection] Fix dumping inlined withers
2 parents 3af7d1d + 455ace0 commit c3f17ac

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ private function addServiceMethodCalls(Definition $definition, string $variableN
754754
$witherAssignation = '';
755755

756756
if ($call[2] ?? false) {
757-
if (null !== $sharedNonLazyId && $lastWitherIndex === $k) {
757+
if (null !== $sharedNonLazyId && $lastWitherIndex === $k && 'instance' === $variableName) {
758758
$witherAssignation = sprintf('$this->%s[\'%s\'] = ', $definition->isPublic() ? 'services' : 'privates', $sharedNonLazyId);
759759
}
760760
$witherAssignation .= sprintf('$%s = ', $variableName);

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,8 @@ public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheSer
14391439
public function testWither()
14401440
{
14411441
$container = new ContainerBuilder();
1442-
$container->register(Foo::class);
1442+
$container->register(Foo::class)
1443+
->setAutowired(true);
14431444

14441445
$container
14451446
->register('wither', Wither::class)

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717

1818
class Foo
1919
{
20+
/**
21+
* @required
22+
* @return static
23+
*/
24+
public function cloneFoo()
25+
{
26+
return clone $this;
27+
}
2028
}
2129

2230
class Bar

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_wither.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function getWitherService()
5555
$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();
5656

5757
$a = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo();
58+
$a = $a->cloneFoo();
5859

5960
$instance = $instance->withFoo1($a);
6061
$this->services['wither'] = $instance = $instance->withFoo2($a);

0 commit comments

Comments
 (0)