diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php index 807fbe748969..6004cc315148 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php @@ -53,7 +53,7 @@ protected function processValue($value, $isRoot = false) $parameters = $r->getParameters(); } - if (isset($key[0]) && '$' !== $key[0] && !class_exists($key)) { + if (isset($key[0]) && '$' !== $key[0] && !class_exists($key) && !interface_exists($key, false)) { throw new InvalidArgumentException(sprintf('Invalid service "%s": did you forget to add the "$" prefix to argument "%s"?', $this->currentId, $key)); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php index 27c0058d2dad..d723951f9873 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveNamedArgumentsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -152,6 +153,19 @@ public function testTypedArgumentWithMissingDollar() $pass->process($container); } + public function testInterfaceTypedArgument() + { + $container = new ContainerBuilder(); + + $definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class); + $definition->setArgument(ContainerInterface::class, $expected = new Reference('foo')); + + $pass = new ResolveNamedArgumentsPass(); + $pass->process($container); + + $this->assertSame($expected, $definition->getArgument(3)); + } + public function testResolvesMultipleArgumentsOfTheSameType() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php index 802ba842715b..74aeb630013f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php @@ -2,12 +2,14 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures; +use Psr\Container\ContainerInterface; + /** * @author Kévin Dunglas */ class NamedArgumentsDummy { - public function __construct(CaseSensitiveClass $c, $apiKey, $hostName) + public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $interface) { }