@@ -55,6 +55,15 @@ public function __construct(bool $throwOnAutowireException = true)
55
55
$ this ->defaultArgument = new class () {
56
56
public $ value ;
57
57
public $ names ;
58
+ public $ bag ;
59
+
60
+ public function withValue (\ReflectionParameter $ parameter ): self
61
+ {
62
+ $ clone = clone $ this ;
63
+ $ clone ->value = $ this ->bag ->escapeValue ($ parameter ->getDefaultValue ());
64
+
65
+ return $ clone ;
66
+ }
58
67
};
59
68
}
60
69
@@ -63,13 +72,16 @@ public function __construct(bool $throwOnAutowireException = true)
63
72
*/
64
73
public function process (ContainerBuilder $ container )
65
74
{
75
+ $ this ->defaultArgument ->bag = $ container ->getParameterBag ();
76
+
66
77
try {
67
78
$ this ->typesClone = clone $ this ;
68
79
parent ::process ($ container );
69
80
} finally {
70
81
$ this ->decoratedClass = null ;
71
82
$ this ->decoratedId = null ;
72
83
$ this ->methodCalls = null ;
84
+ $ this ->defaultArgument ->bag = null ;
73
85
$ this ->defaultArgument ->names = null ;
74
86
$ this ->getPreviousValue = null ;
75
87
$ this ->decoratedMethodIndex = null ;
@@ -275,8 +287,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
275
287
$ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
276
288
277
289
if ($ parameter ->isDefaultValueAvailable ()) {
278
- $ value = clone $ this ->defaultArgument ;
279
- $ value ->value = $ parameter ->getDefaultValue ();
290
+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
280
291
} elseif (!$ parameter ->allowsNull ()) {
281
292
throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
282
293
}
@@ -374,8 +385,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
374
385
}
375
386
376
387
// specifically pass the default value
377
- $ arguments [$ index ] = clone $ this ->defaultArgument ;
378
- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
388
+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
379
389
380
390
continue ;
381
391
}
0 commit comments