Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5f0e2d6

Browse filesBrowse 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
Copy full SHA for 5f0e2d6

File tree

2 files changed

+10
-11
lines changed
Filter options

2 files changed

+10
-11
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php
+6-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php
+4-9Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.