@@ -52,6 +52,15 @@ public function __construct(bool $throwOnAutowireException = true)
52
52
$ this ->defaultArgument = new class () {
53
53
public $ value ;
54
54
public $ names ;
55
+ public $ bag ;
56
+
57
+ public function withValue (\ReflectionParameter $ parameter ): self
58
+ {
59
+ $ clone = clone $ this ;
60
+ $ clone ->value = $ this ->bag ->escapeValue ($ parameter ->getDefaultValue ());
61
+
62
+ return $ clone ;
63
+ }
55
64
};
56
65
}
57
66
@@ -60,13 +69,16 @@ public function __construct(bool $throwOnAutowireException = true)
60
69
*/
61
70
public function process (ContainerBuilder $ container )
62
71
{
72
+ $ this ->defaultArgument ->bag = $ container ->getParameterBag ();
73
+
63
74
try {
64
75
$ this ->typesClone = clone $ this ;
65
76
parent ::process ($ container );
66
77
} finally {
67
78
$ this ->decoratedClass = null ;
68
79
$ this ->decoratedId = null ;
69
80
$ this ->methodCalls = null ;
81
+ $ this ->defaultArgument ->bag = null ;
70
82
$ this ->defaultArgument ->names = null ;
71
83
$ this ->getPreviousValue = null ;
72
84
$ this ->decoratedMethodIndex = null ;
@@ -287,8 +299,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
287
299
}
288
300
289
301
// specifically pass the default value
290
- $ arguments [$ index ] = clone $ this ->defaultArgument ;
291
- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
302
+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
292
303
293
304
continue ;
294
305
}
@@ -298,8 +309,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
298
309
$ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
299
310
300
311
if ($ parameter ->isDefaultValueAvailable ()) {
301
- $ value = clone $ this ->defaultArgument ;
302
- $ value ->value = $ parameter ->getDefaultValue ();
312
+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
303
313
} elseif (!$ parameter ->allowsNull ()) {
304
314
throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
305
315
}
0 commit comments