Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f0e2d6

Browse files
committed
bug #27214 [HttpKernel] Fix services are no longer injected into __invoke controllers method (ogizanagi)
This PR was merged into the 4.1 branch. Discussion ---------- [HttpKernel] Fix services are no longer injected into __invoke controllers method | Q | A | ------------- | --- | Branch? | 4.1 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27208 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A _TL;DR:_ The `RemoveEmptyControllerArgumentLocatorsPass` is the one adding the `Controller::_invoke` => `Controller` shortcut missing from the service locator. It isn't properly executed on some cases. This fixes it. Since #26833, the resolvers are decorated by a `TraceableValueResolver`, which usually isn't much an issue to deal within passes. But the `RemoveEmptyControllerArgumentLocatorsPass` happens late (`TYPE_BEFORE_REMOVING`), when decoration inheritance is already resolved, so accessing `$controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0));` isn't accessing the controller locator, but the decorated service instead. Commits ------- ee44903 [HttpKernel] Fix services are no longer injected into __invoke controllers method
2 parents 906a05c + ee44903 commit 5f0e2d6

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
3333
{
3434
private $resolverServiceId;
3535
private $controllerTag;
36+
private $controllerLocator;
3637

37-
public function __construct(string $resolverServiceId = 'argument_resolver.service', string $controllerTag = 'controller.service_arguments')
38+
public function __construct(string $resolverServiceId = 'argument_resolver.service', string $controllerTag = 'controller.service_arguments', string $controllerLocator = 'argument_resolver.controller_locator')
3839
{
3940
$this->resolverServiceId = $resolverServiceId;
4041
$this->controllerTag = $controllerTag;
42+
$this->controllerLocator = $controllerLocator;
4143
}
4244

4345
public function process(ContainerBuilder $container)
@@ -179,6 +181,8 @@ public function process(ContainerBuilder $container)
179181
}
180182

181183
$container->getDefinition($this->resolverServiceId)
182-
->replaceArgument(0, ServiceLocatorTagPass::register($container, $controllers));
184+
->replaceArgument(0, $controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers));
185+
186+
$container->setAlias($this->controllerLocator, (string) $controllerLocatorRef);
183187
}
184188
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,16 @@
2121
*/
2222
class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
2323
{
24-
private $resolverServiceId;
24+
private $controllerLocator;
2525

26-
public function __construct(string $resolverServiceId = 'argument_resolver.service')
26+
public function __construct(string $controllerLocator = 'argument_resolver.controller_locator')
2727
{
28-
$this->resolverServiceId = $resolverServiceId;
28+
$this->controllerLocator = $controllerLocator;
2929
}
3030

3131
public function process(ContainerBuilder $container)
3232
{
33-
if (false === $container->hasDefinition($this->resolverServiceId)) {
34-
return;
35-
}
36-
37-
$serviceResolver = $container->getDefinition($this->resolverServiceId);
38-
$controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0));
33+
$controllerLocator = $container->findDefinition($this->controllerLocator);
3934
$controllers = $controllerLocator->getArgument(0);
4035

4136
foreach ($controllers as $controller => $argumentRef) {

0 commit comments

Comments
 (0)