[DI] Fix by-type args injection

This commit is contained in:
Nicolas Grekas 2017-11-15 18:44:00 +02:00 committed by Samuel ROZE
parent ecad1c4b3b
commit 2176be74d8
No known key found for this signature in database
GPG Key ID: 835426F55A19FB84

View File

@ -68,15 +68,17 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
throw new InvalidArgumentException(sprintf('Invalid service "%s": the value of argument "%s" of method "%s()" must be null, an instance of %s or an instance of %s, %s given.', $this->currentId, $key, $class !== $this->currentId ? $class.'::'.$method : $method, Reference::class, Definition::class, gettype($argument)));
}
$typeFound = false;
foreach ($parameters as $j => $p) {
if (ProxyHelper::getTypeHint($r, $p, true) === $key) {
if (!array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) {
$resolvedArguments[$j] = $argument;
continue 2;
$typeFound = true;
}
}
throw new InvalidArgumentException(sprintf('Invalid service "%s": method "%s()" has no argument type-hinted as "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
if (!$typeFound) {
throw new InvalidArgumentException(sprintf('Invalid service "%s": method "%s()" has no argument type-hinted as "%s". Check your service definition.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $key));
}
}
if ($resolvedArguments !== $call[1]) {