You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
260
249
continue;
261
250
}
262
-
if (self::MODE_OPTIONAL === $mode && $parameter->isOptional() && !array_key_exists($index, $arguments)) {
251
+
if (!$isConstructor && $parameter->isOptional() && !array_key_exists($index, $arguments)) {
263
252
break;
264
253
}
265
254
if (method_exists($parameter, 'isVariadic') && $parameter->isVariadic()) {
@@ -271,11 +260,7 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
271
260
if (!$typeName) {
272
261
// no default value? Then fail
273
262
if (!$parameter->isOptional()) {
274
-
if (self::MODE_REQUIRED === $mode) {
275
-
thrownewRuntimeException(sprintf('Cannot autowire service "%s": argument $%s of method %s::%s() must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $reflectionMethod->class, $reflectionMethod->name));
276
-
}
277
-
278
-
returnarray();
263
+
thrownewRuntimeException(sprintf('Cannot autowire service "%s": argument $%s of method %s::%s() must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $reflectionMethod->class, $reflectionMethod->name));
279
264
}
280
265
281
266
if (!array_key_exists($index, $arguments)) {
@@ -287,31 +272,24 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
287
272
}
288
273
289
274
if ($value = $this->getAutowiredReference($typeName)) {
$message = sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeName, $this->currentId, $classOrInterface);
299
283
} else {
300
284
$message = sprintf('Cannot autowire argument $%s of method %s::%s() for service "%s": Class %s does not exist.', $parameter->name, $reflectionMethod->class, $reflectionMethod->name, $this->currentId, $typeName);
301
285
}
302
286
303
287
thrownewRuntimeException($message);
304
-
} else {
305
-
returnarray();
306
288
}
307
289
308
290
$arguments[$index] = $value;
309
291
}
310
292
311
-
if (self::MODE_REQUIRED !== $mode && !$didAutowire) {
312
-
returnarray();
313
-
}
314
-
315
293
// it's possible index 1 was set, then index 0, then 2, etc
316
294
// make sure that we re-order so they're injected as expected
* @expectedExceptionMessage Cannot autowire argument $n of method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable() for service "foo": Class Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass does not exist.
0 commit comments