Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb5c0e89

Browse files
pkowalczykfabpot
pkowalczyk
authored andcommitted
[DependencyInjection] Added support for variadics in named arguments
1 parenta135690 commitb5c0e89

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ protected function processValue($value, $isRoot = false)
5555
if (isset($key[0]) &&'$' ===$key[0]) {
5656
foreach ($parametersas$j =>$p) {
5757
if ($key ==='$'.$p->name) {
58-
$resolvedArguments[$j] =$argument;
58+
if ($p->isVariadic() &&\is_array($argument)) {
59+
foreach ($argumentas$variadicArgument) {
60+
$resolvedArguments[$j++] =$variadicArgument;
61+
}
62+
}else {
63+
$resolvedArguments[$j] =$argument;
64+
}
5965

6066
continue2;
6167
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useSymfony\Component\DependencyInjection\Reference;
1818
useSymfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
1919
useSymfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
20+
useSymfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsVariadicsDummy;
2021
useSymfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;
2122

2223
/**
@@ -152,6 +153,36 @@ public function testResolvePrioritizeNamedOverType()
152153

153154
$this->assertEquals(array(newReference('bar'),'qwerty',newReference('foo')),$definition->getArguments());
154155
}
156+
157+
publicfunctiontestVariadics()
158+
{
159+
$container =newContainerBuilder();
160+
161+
$definition =$container->register(NamedArgumentsVariadicsDummy::class, NamedArgumentsVariadicsDummy::class);
162+
$definition->setArguments(
163+
array(
164+
'$class' =>new \stdClass(),
165+
'$variadics' =>array(
166+
newReference('foo'),
167+
newReference('bar'),
168+
newReference('baz'),
169+
),
170+
)
171+
);
172+
173+
$pass =newResolveNamedArgumentsPass();
174+
$pass->process($container);
175+
176+
$this->assertEquals(
177+
array(
178+
0 =>new \stdClass(),
179+
1 =>newReference('foo'),
180+
2 =>newReference('bar'),
181+
3 =>newReference('baz'),
182+
),
183+
$definition->getArguments()
184+
);
185+
}
155186
}
156187

157188
class NoConstructor
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespaceSymfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class NamedArgumentsVariadicsDummy
6+
{
7+
publicfunction__construct(\stdClass$class, ...$variadics)
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp