@@ -58,18 +58,30 @@ public function __construct(bool $throwOnAutowireException = true)
58
58
$ this ->defaultArgument = new class () {
59
59
public $ value ;
60
60
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
+ }
61
70
};
62
71
}
63
72
64
73
public function process (ContainerBuilder $ container )
65
74
{
75
+ $ this ->defaultArgument ->bag = $ container ->getParameterBag ();
76
+
66
77
try {
67
78
$ this ->typesClone = clone $ this ;
68
79
parent ::process ($ container );
69
80
} finally {
70
81
$ this ->decoratedClass = null ;
71
82
$ this ->decoratedId = null ;
72
83
$ this ->methodCalls = null ;
84
+ $ this ->defaultArgument ->bag = null ;
73
85
$ this ->defaultArgument ->names = null ;
74
86
$ this ->getPreviousValue = null ;
75
87
$ this ->decoratedMethodIndex = null ;
@@ -315,8 +327,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
315
327
}
316
328
317
329
// specifically pass the default value
318
- $ arguments [$ index ] = clone $ this ->defaultArgument ;
319
- $ arguments [$ index ]->value = $ parameter ->getDefaultValue ();
330
+ $ arguments [$ index ] = $ this ->defaultArgument ->withValue ($ parameter );
320
331
321
332
continue ;
322
333
}
@@ -326,8 +337,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
326
337
$ failureMessage = $ this ->createTypeNotFoundMessageCallback ($ ref , sprintf ('argument "$%s" of method "%s()" ' , $ parameter ->name , $ class !== $ this ->currentId ? $ class .':: ' .$ method : $ method ));
327
338
328
339
if ($ parameter ->isDefaultValueAvailable ()) {
329
- $ value = clone $ this ->defaultArgument ;
330
- $ value ->value = $ parameter ->getDefaultValue ();
340
+ $ value = $ this ->defaultArgument ->withValue ($ parameter );
331
341
} elseif (!$ parameter ->allowsNull ()) {
332
342
throw new AutowiringFailedException ($ this ->currentId , $ failureMessage );
333
343
}
0 commit comments