[HttpKernel] Fix services are no longer injected into __invoke controllers method#27214
Merged
fabpot merged 1 commit intosymfony:4.1from May 14, 2018
ogizanagi:fix/service_arg_invokable_controller
Merged
[HttpKernel] Fix services are no longer injected into __invoke controllers method#27214fabpot merged 1 commit intosymfony:4.1from ogizanagi:fix/service_arg_invokable_controller
fabpot merged 1 commit intosymfony:4.1from
ogizanagi:fix/service_arg_invokable_controller
Conversation
nicolas-grekas
approved these changes
May 10, 2018
Member
nicolas-grekas
left a comment
There was a problem hiding this comment.
(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); |
Member
There was a problem hiding this comment.
Being private is already the default, isn't it?
Contributor
Author
|
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 |
fabpot
approved these changes
May 14, 2018
Member
|
Thank you @ogizanagi. |
fabpot
added a commit
that referenced
this pull request
May 14, 2018
…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
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: The
RemoveEmptyControllerArgumentLocatorsPassis the one adding theController::_invoke=>Controllershortcut 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 theRemoveEmptyControllerArgumentLocatorsPasshappens 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.