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 (!$reflectionMethod->getNumberOfParameters()) {
220
+
continue; // skip getters
238
221
}
222
+
if (!$reflectionMethod->isPublic()) {
223
+
thrownewRuntimeException(sprintf('Cannot autowire service "%s": method %s::%s() must be public.', $this->currentId, $reflectionClass->name, $reflectionMethod->name));
if (!$isConstructor && !$arguments && !$reflectionMethod->getNumberOfRequiredParameters()) {
246
+
thrownewRuntimeException(sprintf('Cannot autowire service "%s": method %s::%s() has only optional arguments, thus must be wired explicitly.', $this->currentId, $reflectionMethod->class, $reflectionMethod->name));
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
260
251
continue;
261
252
}
262
-
if (self::MODE_OPTIONAL === $mode && $parameter->isOptional() && !array_key_exists($index, $arguments)) {
253
+
if (!$isConstructor && $parameter->isOptional() && !array_key_exists($index, $arguments)) {
263
254
break;
264
255
}
265
256
if (method_exists($parameter, 'isVariadic') && $parameter->isVariadic()) {
@@ -271,11 +262,7 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
271
262
if (!$typeName) {
272
263
// no default value? Then fail
273
264
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();
265
+
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
266
}
280
267
281
268
if (!array_key_exists($index, $arguments)) {
@@ -287,31 +274,24 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
287
274
}
288
275
289
276
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
285
} else {
300
286
$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
287
}
302
288
303
289
thrownewRuntimeException($message);
304
-
} else {
305
-
returnarray();
306
290
}
307
291
308
292
$arguments[$index] = $value;
309
293
}
310
294
311
-
if (self::MODE_REQUIRED !== $mode && !$didAutowire) {
312
-
returnarray();
313
-
}
314
-
315
295
// it's possible index 1 was set, then index 0, then 2, etc
316
296
// make sure that we re-order so they're injected as expected
317
297
ksort($arguments);
@@ -330,16 +310,24 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
thrownewRuntimeException(sprintf('Cannot autowire service "%s": getter %s::%s() must%s be given a return value explicitly.', $this->currentId, $reflectionMethod->class, $reflectionMethod->name, $typeName ? '' : ' have a return-type hint or'));
320
+
}
321
+
322
+
if (!$typeRef = $this->getAutowiredReference($typeName)) {
$message = sprintf('Unable to autowire return type "%s" for service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeName, $this->currentId, $classOrInterface);
325
+
} else {
326
+
$message = sprintf('Cannot autowire return type of getter %s::%s() for service "%s": Class %s does not exist.', $reflectionMethod->class, $reflectionMethod->name, $this->currentId, $typeName);
array('setNotAutowireable', '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.'),
720
+
array('setBar', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setBar() has only optional arguments, thus must be wired explicitly.'),
721
+
array('setOptionalNotAutowireable', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalNotAutowireable() has only optional arguments, thus must be wired explicitly.'),
722
+
array('setOptionalNoTypeHint', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalNoTypeHint() has only optional arguments, thus must be wired explicitly.'),
723
+
array('setOptionalArgNoAutowireable', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalArgNoAutowireable() has only optional arguments, thus must be wired explicitly.'),
724
+
array(null, 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod() must be public.'),
725
+
);
726
+
}
710
727
}
711
728
712
729
class Foo
@@ -917,43 +934,6 @@ public function setDependencies(Foo $foo, A $a)
0 commit comments