8000 bug #22330 [HttpKernel] Resolve invokable controllers short notations… · sstok/symfony@ec2cc08 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec2cc08

Browse files
committed
bug symfony#22330 [HttpKernel] Resolve invokable controllers short notations using ServiceValueResolver (chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- [HttpKernel] Resolve invokable controllers short notations using ServiceValueResolver | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#22202 | License | MIT | Doc PR | n/a Register the service id as an alias of `id:__invoke` so that using the invokable short notation (id only) triggers the ServiceArgumentResolver. Commits ------- 717fa85 Resolve invokable controllers short notations using ServiceValueResolver
2 parents 549af73 + 717fa85 commit ec2cc08

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public function process(ContainerBuilder $container)
6060
if ($controllerDef->getClass() === $id) {
6161
$controllers[$id.'::'.$action] = $argumentRef;
6262
}
63+
if ('__invoke' === $action) {
64+
$controllers[$id] = $argumentRef;
65+
}
6366
continue;
6467
}
6568
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,44 @@ public function testSameIdClass()
7878
);
7979
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
8080
}
81+
82+
public function testInvoke()
83+
{
84+
$container = new ContainerBuilder();
85+
$resolver = $container->register('argument_resolver.service')->addArgument(array());
86+
87+
$container->register('invokable', InvokableRegisterTestController::class)
88+
->addTag('controller.service_arguments')
89+
;
90+
91+
(new RegisterControllerArgumentLocatorsPass())->process($container);
92+
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
93+
94+
$this->assertEquals(
95+
array('invokable:__invoke', 'invokable'),
96+
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
97+
);
98+
}
99+
100+
public function testInvokeSameIdClass()
101+
{
102+
$container = new ContainerBuilder();
103+
$resolver = $container->register('argument_resolver.service')->addArgument(array());
104+
105+
$container->register(InvokableRegisterTestController::class, InvokableRegisterTestController::class)
106+
->addTag('controller.service_arguments')
107+
;
108+
109+
(new RegisterControllerArgumentLocatorsPass())->process($container);
110+
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
111+
112+
$expected = array(
113+
InvokableRegisterTestController::class.':__invoke',
114+
InvokableRegisterTestController::class.'::__invoke',
115+
InvokableRegisterTestController::class,
116+
);
117+
$this->assertEquals($expected, array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0)));
118+
}
81119
}
82120

83121
class RemoveTestController1
@@ -97,3 +135,10 @@ public function fooAction(NotFound $bar)
97135
{
98136
}
99137
}
138+
139+
class InvokableRegisterTestController
140+
{
141+
public function __invoke(\stdClass $bar)
142+
{
143+
}
144+
}

0 commit comments

Comments
 (0)
0