@@ -55,6 +55,15 @@ public function __construct(bool $throwOnAutowireException = true)
5555 $ this ->defaultArgument = new class () {
5656 public $ value ;
5757 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+ }
5867 };
5968 }
6069
@@ -63,13 +72,16 @@ public function __construct(bool $throwOnAutowireException = true)
6372 */
6473 public function process (ContainerBuilder $ container )
6574 {
75+ $ this ->defaultArgument ->bag = $ container ->getParameterBag ();
76+
6677 try {
6778 $ this ->typesClone = clone $ this ;
6879 parent ::process ($ container );
6980 } finally {
7081 $ this ->decoratedClass = null ;
7182 $ this ->decoratedId = null ;
7283 $ this ->methodCalls = null ;
84+ $ this ->defaultArgument ->bag = null ;
7385 $ this ->defaultArgument ->names = null ;
7486 $ this ->getPreviousValue = null ;
7587 $ this ->decoratedMethodIndex = null ;
@@ -275,8 +287,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
275287 $ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
276288
277289 if ($ parameter ->isDefaultValueAvailable ()) {
278- $ value = clone $ this ->defaultArgument ;
279- $ value ->value = $ parameter ->getDefaultValue ();
290+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
280291 } elseif (!$ parameter ->allowsNull ()) {
281292 throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
282293 }
@@ -374,8 +385,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
374385 }
375386
376387 // specifically pass the default value
377- $ arguments [$ index ] = clone $ this ->defaultArgument ;
378- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
388+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
379389
380390 continue ;
381391 }
0 commit comments