-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Parse the _controller format in sub-requests #23013
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
Conversation
e36a036 to
89c6891
Compare
|
Another solution would be to resolve the controller name with the This would remove the BC break. |
| <tag name="kernel.event_subscriber" /> | ||
| </service> | ||
|
|
||
| <service id="resolve_controller_name_subscriber" class="Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber" public="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.
should not be public. Listeners can be private now, and there is no BC issue about making this one private as it is new
| public static function getSubscribedEvents() | ||
| { | ||
| return array( | ||
| KernelEvents::REQUEST => array(array('onKernelRequest', 24)), |
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.
you can simplify this as array('onKernelRequest', 24)
8530c9e to
3856932
Compare
3856932 to
9578fd3
Compare
|
@jvasseur I really like that idea... but the In the mean time, I've made updates from Stof's comments! |
nicolas-grekas
left a comment
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.
👍
|
Thank you @weaverryan. |
This PR was merged into the 3.3 branch. Discussion ---------- Parse the _controller format in sub-requests | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | possibly (edge case) | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22966 | License | MIT | Doc PR | n/a As mentioned on the issue (#22966 (comment)), the new "controller service args" functionality relies on the `_controller` attribute to be in either the service format `App\Controller\Foo:bar` or at least the final parsed format `App\Controller\Foo::bar`. But when you make a sub-request with the `App:Foo:bar` format, the `ControllerResolver` correctly parses this, but the `_controller` request attribute will always contain the original `App:Foo:bar` format. That causes the `ServiceValueResolver` to fail. The only way I can think to fix this - reliably - is to parse the `_controller` attribute in a listener. And this, works great! Notes: A) There is a small chance for a BC break: if you were relying on the `_controller` old format in a `kernel.request` format in the framework, in a listener between the priority of 25 and 31 for sub-requests (because normal requests have `_controller` normalized during routing)... then you will see a behavior change. B) We could load the `ControllerNameParser` lazily via a service locator. C) We could deprecate calling the parser in the FW's `ControllerResolver`. Along with (B), I think it would (in 4.0) mean that the `ControllerNameParser` is not instantiated at runtime (except for sub-requests). If someone can think of a different/better solution, please let me know! Cheers! Commits ------- 9578fd3 Adding a new event subscriber that "parses" the _controller attribute in the FW
As mentioned on the issue (#22966 (comment)), the new "controller service args" functionality relies on the
_controllerattribute to be in either the service formatApp\Controller\Foo:baror at least the final parsed formatApp\Controller\Foo::bar. But when you make a sub-request with theApp:Foo:barformat, theControllerResolvercorrectly parses this, but the_controllerrequest attribute will always contain the originalApp:Foo:barformat. That causes theServiceValueResolverto fail.The only way I can think to fix this - reliably - is to parse the
_controllerattribute in a listener. And this, works great! Notes:A) There is a small chance for a BC break: if you were relying on the
_controllerold format in akernel.requestformat in the framework, in a listener between the priority of 25 and 31 for sub-requests (because normal requests have_controllernormalized during routing)... then you will see a behavior change.B) We could load the
ControllerNameParserlazily via a service locator.C) We could deprecate calling the parser in the FW's
ControllerResolver. Along with (B), I think it would (in 4.0) mean that theControllerNameParseris not instantiated at runtime (except for sub-requests).If someone can think of a different/better solution, please let me know!
Cheers!