File tree 3 files changed +36
-1
lines changed
src/Symfony/Component/DependencyInjection
3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -338,10 +338,11 @@ private static function getResourceMetadataForMethod(\ReflectionMethod $method)
338
338
$ class = false ;
339
339
}
340
340
341
+ $ isVariadic = method_exists ($ parameter , 'isVariadic ' ) && $ parameter ->isVariadic ();
341
342
$ methodArgumentsMetadata [] = array (
342
343
'class ' => $ class ,
343
344
'isOptional ' => $ parameter ->isOptional (),
344
- 'defaultValue ' => $ parameter ->isOptional () ? $ parameter ->getDefaultValue () : null ,
345
+ 'defaultValue ' => ( $ parameter ->isOptional () && ! $ isVariadic ) ? $ parameter ->getDefaultValue () : null ,
345
346
);
346
347
}
347
348
Original file line number Diff line number Diff line change 14
14
use Symfony \Component \DependencyInjection \Compiler \AutowirePass ;
15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
16
use Symfony \Component \DependencyInjection \Reference ;
17
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \includes \FooVariadic ;
17
18
18
19
/**
19
20
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -35,6 +36,23 @@ public function testProcess()
35
36
$ this ->assertEquals ('foo ' , (string ) $ container ->getDefinition ('bar ' )->getArgument (0 ));
36
37
}
37
38
39
+ /**
40
+ * @requires PHP 5.6
41
+ */
42
+ public function testProcessVariadic ()
43
+ {
44
+ $ container = new ContainerBuilder ();
45
+ $ container ->register ('foo ' , Foo::class);
46
+ $ definition = $ container ->register ('fooVariadic ' , FooVariadic::class);
47
+ $ definition ->setAutowired (true );
48
+
49
+ $ pass = new AutowirePass();
50
+ $ pass ->process ($ container );
51
+
52
+ $ this ->assertCount (1 , $ container ->getDefinition ('fooVariadic ' )->getArguments ());
53
+ $ this ->assertEquals ('foo ' , (string ) $ container ->getDefinition ('fooVariadic ' )->getArgument (0 ));
54
+ }
55
+
38
56
public function testProcessAutowireParent ()
39
57
{
40
58
$ container = new ContainerBuilder ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \DependencyInjection \Tests \Fixtures \includes ;
4
+
5
+ use Symfony \Component \DependencyInjection \Tests \Compiler \Foo ;
6
+
7
+ class FooVariadic
8
+ {
9
+ public function __construct (Foo $ foo )
10
+ {
11
+ }
12
+
13
+ public function bar (...$ arguments )
14
+ {
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments