Skip to content

Commit 34302da

Browse files
Merge branch '5.4' into 6.0
* 5.4: [DependencyInjection] Fix named arguments when using ContainerBuilder before compilation
2 parents 0b6e015 + 99dae35 commit 34302da

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

ContainerBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ private function createService(Definition $definition, array &$inlineServices, b
10221022
return $this->services[$id] ?? $this->privates[$id];
10231023
}
10241024

1025+
if (!array_is_list($arguments)) {
1026+
$arguments = array_combine(array_map(function ($k) { return preg_replace('/^.*\\$/', '', $k); }, array_keys($arguments)), $arguments);
1027+
}
1028+
10251029
if (null !== $factory) {
10261030
$service = $factory(...$arguments);
10271031

Tests/ContainerBuilderTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,10 +1732,7 @@ public function testFindTags()
17321732
$this->assertSame(['tag1', 'tag2', 'tag3'], $container->findTags());
17331733
}
17341734

1735-
/**
1736-
* @requires PHP 8
1737-
*/
1738-
public function testNamedArgument()
1735+
public function testNamedArgumentAfterCompile()
17391736
{
17401737
$container = new ContainerBuilder();
17411738
$container->register(E::class)
@@ -1749,6 +1746,18 @@ public function testNamedArgument()
17491746
$this->assertSame('', $e->first);
17501747
$this->assertSame(2, $e->second);
17511748
}
1749+
1750+
public function testNamedArgumentBeforeCompile()
1751+
{
1752+
$container = new ContainerBuilder();
1753+
$container->register(E::class, E::class)
1754+
->setPublic(true)
1755+
->setArguments(['$first' => 1]);
1756+
1757+
$e = $container->get(E::class);
1758+
1759+
$this->assertSame(1, $e->first);
1760+
}
17521761
}
17531762

17541763
class FooClass

0 commit comments

Comments
 (0)