Skip to content

Commit 6abd565

Browse files
Merge branch '6.1' into 6.2
* 6.1: [DependencyInjection] Fix named arguments when using ContainerBuilder before compilation
2 parents cacedfc + 6ff7b7d commit 6abd565

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ContainerBuilder.php

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

1036+
if (!array_is_list($arguments)) {
1037+
$arguments = array_combine(array_map(function ($k) { return preg_replace('/^.*\\$/', '', $k); }, array_keys($arguments)), $arguments);
1038+
}
1039+
10361040
if (null !== $factory) {
10371041
$service = $factory(...$arguments);
10381042

Tests/ContainerBuilderTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ public function testFindTags()
18301830
$this->assertSame(['tag1', 'tag2', 'tag3'], $container->findTags());
18311831
}
18321832

1833-
public function testNamedArgument()
1833+
public function testNamedArgumentAfterCompile()
18341834
{
18351835
$container = new ContainerBuilder();
18361836
$container->register(E::class)
@@ -1844,6 +1844,18 @@ public function testNamedArgument()
18441844
$this->assertSame('', $e->first);
18451845
$this->assertSame(2, $e->second);
18461846
}
1847+
1848+
public function testNamedArgumentBeforeCompile()
1849+
{
1850+
$container = new ContainerBuilder();
1851+
$container->register(E::class, E::class)
1852+
->setPublic(true)
1853+
->setArguments(['$first' => 1]);
1854+
1855+
$e = $container->get(E::class);
1856+
1857+
$this->assertSame(1, $e->first);
1858+
}
18471859
}
18481860

18491861
class FooClass

0 commit comments

Comments
 (0)