diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index b1c24d5b3962b..8fd1f553e0030 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -192,7 +192,7 @@ public function process(ContainerBuilder $container) $args[$p->name] = new Reference($erroredId, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE); } else { $target = ltrim($target, '\\'); - $args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior, $p->name) : new Reference($target, $invalidBehavior); + $args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior, Target::parseName($p)) : new Reference($target, $invalidBehavior); } } // register the maps as a per-method service-locators diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index b3a750e953398..1e3d25d440f5c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -428,6 +428,9 @@ public function testBindWithTarget() $container = new ContainerBuilder(); $resolver = $container->register('argument_resolver.service')->addArgument([]); + $container->register(ControllerDummy::class, 'bar'); + $container->register(ControllerDummy::class.' $imageStorage', 'baz'); + $container->register('foo', WithTarget::class) ->setBindings(['string $someApiKey' => new Reference('the_api_key')]) ->addTag('controller.service_arguments'); @@ -437,7 +440,11 @@ public function testBindWithTarget() $locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0); $locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]); - $expected = ['apiKey' => new ServiceClosureArgument(new Reference('the_api_key'))]; + $expected = [ + 'apiKey' => new ServiceClosureArgument(new Reference('the_api_key')), + 'service1' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'imageStorage')), + 'service2' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'service2')), + ]; $this->assertEquals($expected, $locator->getArgument(0)); } } @@ -513,7 +520,10 @@ class WithTarget { public function fooAction( #[Target('some.api.key')] - string $apiKey + string $apiKey, + #[Target('image.storage')] + ControllerDummy $service1, + ControllerDummy $service2 ) { } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: