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