-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Fix services are no longer injected into __invoke controllers method #27214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HttpKernel] Fix services are no longer injected into __invoke controllers method #27214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(with minor comment, maybe add a test if worth it?)
->replaceArgument(0, ServiceLocatorTagPass::register($container, $controllers)); | ||
->replaceArgument(0, $controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers)); | ||
|
||
$container->setAlias($this->controllerLocator, (string) $controllerLocatorRef)->setPrivate(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being private is already the default, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, indeed.
Not sure which kind of tests would be really relevant here, nor if it is worth the hassle :) |
+1, just ran into that issue too after updating to 4.1 beta |
Thank you @ogizanagi. |
…voke 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
TL;DR: The
RemoveEmptyControllerArgumentLocatorsPass
is the one adding theController::_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 theRemoveEmptyControllerArgumentLocatorsPass
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.