Skip to content

Commit

Permalink
Merge branch '6.0' into 6.1
Browse files Browse the repository at this point in the history
* 6.0:
  [DependencyInjection] Fix named arguments when using ContainerBuilder before compilation
  • Loading branch information
nicolas-grekas committed Jan 23, 2023
2 parents 69f78fe + 34302da commit 6ff7b7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,10 @@ private function createService(Definition $definition, array &$inlineServices, b
return $this->services[$id] ?? $this->privates[$id];
}

if (!array_is_list($arguments)) {
$arguments = array_combine(array_map(function ($k) { return preg_replace('/^.*\\$/', '', $k); }, array_keys($arguments)), $arguments);
}

if (null !== $factory) {
$service = $factory(...$arguments);

Expand Down
14 changes: 13 additions & 1 deletion Tests/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ public function testFindTags()
$this->assertSame(['tag1', 'tag2', 'tag3'], $container->findTags());
}

public function testNamedArgument()
public function testNamedArgumentAfterCompile()
{
$container = new ContainerBuilder();
$container->register(E::class)
Expand All @@ -1777,6 +1777,18 @@ public function testNamedArgument()
$this->assertSame('', $e->first);
$this->assertSame(2, $e->second);
}

public function testNamedArgumentBeforeCompile()
{
$container = new ContainerBuilder();
$container->register(E::class, E::class)
->setPublic(true)
->setArguments(['$first' => 1]);

$e = $container->get(E::class);

$this->assertSame(1, $e->first);
}
}

class FooClass
Expand Down

0 comments on commit 6ff7b7d

Please sign in to comment.