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

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

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

weaverryan
Copy link
Member

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!

@jvasseur
Copy link
Contributor

jvasseur commented Jun 1, 2017

Another solution would be to resolve the controller name with the ControllerNameParser in the ServiceValueResolver.

This would remove the BC break.

@@ -70,5 +70,10 @@
<service id="validate_request_listener" class="Symfony\Component\HttpKernel\EventListener\ValidateRequestListener" public="true">
<tag name="kernel.event_subscriber" />
</service>

<service id="resolve_controller_name_subscriber" class="Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber" public="true">
Copy link
Member

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)),
Copy link
Member

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)

@weaverryan weaverryan force-pushed the normalize-controller-format branch 2 times, most recently from 8530c9e to 3856932 Compare June 1, 2017 13:59
@weaverryan weaverryan force-pushed the normalize-controller-format branch from 3856932 to 9578fd3 Compare June 1, 2017 14:00
@weaverryan
Copy link
Member Author

@jvasseur I really like that idea... but the ServiceValueResolver is in the component, and the ControllerNameParser is in the framework only. So, this approach is still a valid alternative. Specifically, instead of a subscriber, we would sub-class the ServiceValueResolver in the FW to parse the controller string. Do people like that better?

In the mean time, I've made updates from Stof's comments!

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jun 2, 2017
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fabpot
Copy link
Member

fabpot commented Jun 2, 2017

Thank you @weaverryan.

@fabpot fabpot merged commit 9578fd3 into symfony:3.3 Jun 2, 2017
fabpot added a commit that referenced this pull request Jun 2, 2017
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
@weaverryan weaverryan deleted the normalize-controller-format branch June 4, 2017 13:52
@fabpot fabpot mentioned this pull request Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.