Skip to content

Commit 6ff7b7d

Browse files
Merge branch '6.0' into 6.1
* 6.0: [DependencyInjection] Fix named arguments when using ContainerBuilder before compilation
2 parents 69f78fe + 34302da commit 6ff7b7d

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
@@ -1029,6 +1029,10 @@ private function createService(Definition $definition, array &$inlineServices, b
10291029
return $this->services[$id] ?? $this->privates[$id];
10301030
}
10311031

1032+
if (!array_is_list($arguments)) {
1033+
$arguments = array_combine(array_map(function ($k) { return preg_replace('/^.*\\$/', '', $k); }, array_keys($arguments)), $arguments);
1034+
}
1035+
10321036
if (null !== $factory) {
10331037
$service = $factory(...$arguments);
10341038

Tests/ContainerBuilderTest.php

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

1766-
public function testNamedArgument()
1766+
public function testNamedArgumentAfterCompile()
17671767
{
17681768
$container = new ContainerBuilder();
17691769
$container->register(E::class)
@@ -1777,6 +1777,18 @@ public function testNamedArgument()
17771777
$this->assertSame('', $e->first);
17781778
$this->assertSame(2, $e->second);
17791779
}
1780+
1781+
public function testNamedArgumentBeforeCompile()
1782+
{
1783+
$container = new ContainerBuilder();
1784+
$container->register(E::class, E::class)
1785+
->setPublic(true)
1786+
->setArguments(['$first' => 1]);
1787+
1788+
$e = $container->get(E::class);
1789+
1790+
$this->assertSame(1, $e->first);
1791+
}
17801792
}
17811793

17821794
class FooClass

0 commit comments

Comments
 (0)