Skip to content

Commit

Permalink
[HttpKernel] fix using Target with controller args
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Mar 7, 2022
1 parent 6a51913 commit aa5ddc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -513,7 +520,10 @@ class WithTarget
{
public function fooAction(
#[Target('some.api.key')]
string $apiKey
string $apiKey,
#[Target('image.storage')]
ControllerDummy $service1,
ControllerDummy $service2
) {
}
}

0 comments on commit aa5ddc5

Please sign in to comment.