@@ -58,18 +58,30 @@ public function __construct(bool $throwOnAutowireException = true)
5858 $ this ->defaultArgument = new class () {
5959 public $ value ;
6060 public $ names ;
61+ public $ bag ;
62+
63+ public function withValue (\ReflectionParameter $ parameter ): self
64+ {
65+ $ clone = clone $ this ;
66+ $ clone ->value = $ this ->bag ->escapeValue ($ parameter ->getDefaultValue ());
67+
68+ return $ clone ;
69+ }
6170 };
6271 }
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 ;
@@ -315,8 +327,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
315327 }
316328
317329 // specifically pass the default value
318- $ arguments [$ index ] = clone $ this ->defaultArgument ;
319- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
330+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
320331
321332 continue ;
322333 }
@@ -326,8 +337,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
326337 $ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
327338
328339 if ($ parameter ->isDefaultValueAvailable ()) {
329- $ value = clone $ this ->defaultArgument ;
330- $ value ->value = $ parameter ->getDefaultValue ();
340+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
331341 } elseif (!$ parameter ->allowsNull ()) {
332342 throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
333343 }
0 commit comments