Skip to content

Commit 2176be7

Browse files
nicolas-grekassroze
authored andcommitted
[DI] Fix by-type args injection
1 parent ecad1c4 commit 2176be7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ protected function processValue($value, $isRoot = false)
6868
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)));
6969
}
7070

71+
$typeFound = false;
7172
foreach ($parameters as $j => $p) {
72-
if (ProxyHelper::getTypeHint($r, $p, true) === $key) {
73+
if (!array_key_exists($j, $resolvedArguments) && ProxyHelper::getTypeHint($r, $p, true) === $key) {
7374
$resolvedArguments[$j] = $argument;
74-
75-
continue 2;
75+
$typeFound = true;
7676
}
7777
}
7878

79-
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));
79+
if (!$typeFound) {
80+
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));
81+
}
8082
}
8183

8284
if ($resolvedArguments !== $call[1]) {

0 commit comments

Comments
 (0)