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 (!$isConstructor && !$arguments&& !$reflectionMethod->getNumberOfRequiredParameters()) {
238
-
thrownewRuntimeException(sprintf('Cannot autowire service "%s": method %s() has only optional arguments, thus must be wired explicitly.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
235
+
$parameters = $reflectionMethod->getParameters();
236
+
if (method_exists<
10000
/span>('ReflectionMethod', 'isVariadic') && $reflectionMethod->isVariadic()) {
237
+
array_pop($parameters);
239
238
}
240
239
$parameters = $reflectionMethod->getParameters();
241
240
if (method_exists('ReflectionMethod', 'isVariadic') && $reflectionMethod->isVariadic()) {
@@ -246,9 +245,6 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
246
245
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
247
246
continue;
248
247
}
249
-
if (!$isConstructor && $parameter->isOptional() && !array_key_exists($index, $arguments)) {
@@ -258,7 +254,7 @@ private function autowireMethod(\ReflectionMethod $reflectionMethod, array $argu
258
254
}
259
255
260
256
// no default value? Then fail
261
-
if (!$parameter->isOptional()) {
257
+
if (!$parameter->isDefaultValueAvailable()) {
262
258
thrownewRuntimeException(sprintf('Cannot autowire service "%s": argument $%s of method %s() must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
* @expectedExceptionMessage Cannot autowire service "not_really_optional_scalar": argument $foo of method Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArgumentsOptionalScalarNotReallyOptional::__construct() must have a type-hint or be given a value explicitly.
@@ -659,10 +662,6 @@ public function provideNotWireableCalls()
659
662
{
660
663
returnarray(
661
664
array('setNotAutowireable', 'Cannot autowire service "foo": argument $n of method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable() has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist.'),
662
-
array('setBar', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setBar() has only optional arguments, thus must be wired explicitly.'),
663
-
array('setOptionalNotAutowireable', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalNotAutowireable() has only optional arguments, thus must be wired explicitly.'),
664
-
array('setOptionalNoTypeHint', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalNoTypeHint() has only optional arguments, thus must be wired explicitly.'),
665
-
array('setOptionalArgNoAutowireable', 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setOptionalArgNoAutowireable() has only optional arguments, thus must be wired explicitly.'),
666
665
array(null, 'Cannot autowire service "foo": method Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod() must be public.'),
0 commit comments