Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8d641d7

Browse filesBrowse files
Merge branch '6.1' into 6.2
* 6.1: [DependencyInjection] Fix named arguments when using ContainerBuilder before compilation
2 parents 50e6dc7 + 116d8a2 commit 8d641d7
Copy full SHA for 8d641d7

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+4Lines 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

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+13-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.