Skip to content

Commit 448cc3a

Browse files
committed
[HttpKernel] fix using Target with controller args
1 parent 2da78ce commit 448cc3a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function process(ContainerBuilder $container)
192192
$args[$p->name] = new Reference($erroredId, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE);
193193
} else {
194194
$target = ltrim($target, '\\');
195-
$args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior, $p->name) : new Reference($target, $invalidBehavior);
195+
$args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior, Target::parseName($p)) : new Reference($target, $invalidBehavior);
196196
}
197197
}
198198
// register the maps as a per-method service-locators

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ public function testBindWithTarget()
428428
$container = new ContainerBuilder();
429429
$resolver = $container->register('argument_resolver.service')->addArgument([]);
430430

431+
$container->register(ControllerDummy::class, 'bar');
432+
$container->register(ControllerDummy::class.' $imageStorage', 'baz');
433+
431434
$container->register('foo', WithTarget::class)
432435
->setBindings(['string $someApiKey' => new Reference('the_api_key')])
433436
->addTag('controller.service_arguments');
@@ -437,7 +440,11 @@ public function testBindWithTarget()
437440
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
438441
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
439442

440-
$expected = ['apiKey' => new ServiceClosureArgument(new Reference('the_api_key'))];
443+
$expected = [
444+
'apiKey' => new ServiceClosureArgument(new Reference('the_api_key')),
445+
'service1' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'imageStorage')),
446+
'service2' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'service2')),
447+
];
441448
$this->assertEquals($expected, $locator->getArgument(0));
442449
}
443450
}
@@ -513,7 +520,10 @@ class WithTarget
513520
{
514521
public function fooAction(
515522
#[Target('some.api.key')]
516-
string $apiKey
523+
string $apiKey,
524+
#[Target('image.storage')]
525+
ControllerDummy $service1,
526+
ControllerDummy $service2
517527
) {
518528
}
519529
}

0 commit comments

Comments
 (0)