8000 Resolve invokable controllers short notations using ServiceValueResolver · Nek-/symfony@717fa85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 717fa85

Browse files
committed
Resolve invokable controllers short notations using ServiceValueResolver
1 parent 549af73 commit 717fa85

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