2222use Symfony \Component \DependencyInjection \Exception \AutowiringFailedException ;
2323use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
2424use Symfony \Component \DependencyInjection \LazyProxy \ProxyHelper ;
25+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
2526use Symfony \Component \DependencyInjection \TypedReference ;
2627
2728/**
@@ -52,6 +53,15 @@ public function __construct(bool $throwOnAutowireException = true)
5253 $ this ->defaultArgument = new class () {
5354 public $ value ;
5455 public $ names ;
56+ public $ bag ;
57+
58+ public function withValue (\ReflectionParameter $ parameter ): self
59+ {
60+ $ clone = clone $ this ;
61+ $ clone ->value = $ this ->bag ->escapeValue ($ parameter ->getDefaultValue ());
62+
63+ return $ clone ;
64+ }
5565 };
5666 }
5767
@@ -60,13 +70,16 @@ public function __construct(bool $throwOnAutowireException = true)
6070 */
6171 public function process (ContainerBuilder $ container )
6272 {
73+ $ this ->defaultArgument ->bag = $ container ->getParameterBag ();
74+
6375 try {
6476 $ this ->typesClone = clone $ this ;
6577 parent ::process ($ container );
6678 } finally {
6779 $ this ->decoratedClass = null ;
6880 $ this ->decoratedId = null ;
6981 $ this ->methodCalls = null ;
82+ $ this ->defaultArgument ->bag = null ;
7083 $ this ->defaultArgument ->names = null ;
7184 $ this ->getPreviousValue = null ;
7285 $ this ->decoratedMethodIndex = null ;
@@ -287,8 +300,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
287300 }
288301
289302 // specifically pass the default value
290- $ arguments [$ index ] = clone $ this ->defaultArgument ;
291- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
303+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
292304
293305 continue ;
294306 }
@@ -298,8 +310,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
298310 $ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
299311
300312 if ($ parameter ->isDefaultValueAvailable ()) {
301- $ value = clone $ this ->defaultArgument ;
302- $ value ->value = $ parameter ->getDefaultValue ();
313+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
303314 } elseif (!$ parameter ->allowsNull ()) {
304315 throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
305316 }
0 commit comments