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
[WIP] accept header based selection of the controller #561
Conversation
…roller developed together with @newLoki
Shouldn't we wait the ExpressionLanguage component? |
why wait? i mean its here already. are you talking about being able to embed the relevant logic into the routing via the EL? |
Ja. I would like to create different route definitions rather than a single one with a looooong configuration section. |
What about using version constraints like in composer instead ? EDIT: missed the description, sorry |
@willdurand Would it be really longer than 2 route definitions duplicating everything except the controller ? I don't expect the controller map to contain tens of entries |
Hm, why isnt the version set as a request attributes, and then matched as a regular route requirement ? (Do you think it is possible to translate a version constraint to a regex ?) |
@adrienbrault this would work if you have the version as a placeholder in the url (and you don't need anything special for it as the routing component alone can handle it). the goal of this PR is to select the version based on the Accept header, not based on some URL placeholder. |
@adrienbrault see also the discussion after this post #136 (comment) furthermore .. the regexp based version thingi is just an example. i think it would make sense to provide several and of course the matching could be done by full media type without any regexp at all. |
So now my understanding is:
|
With an @stof sure but they are not the same routes after all, so having two different definitions would make sense. It is already the case with the HTTP method.. |
@willdurand If you want to use multiple routes, you don't need this PR at all. |
Care to elaborate? And, is |
no, it is not released yet. |
Then we would just need a way to add negotiation functions to the routing expression language right ? hello_version_v1:
pattern: /liip/version
defaults:
_controller: 'liip_hello.world.controller:v1Action'
_format: json
condition: 'matchesVersion(request, "1.*")'
hello_version_v2:
pattern: /liip/version
defaults:
_controller: 'liip_hello.world.controller:v2Action'
_format: json
condition: 'matchesVersion(request, "2.*")' Though I would not like having multiple routes that would generate the same path. Right now it does not seem easy add functions because : https://github.com/symfony/symfony/blob/5ebaad33e6b6e01b46afb86a9370dfe7e5d136c0/src/Symfony/Component/Routing/Matcher/UrlMatcher.php#L235-L245 |
for more information about conditions in the routing layer see http://symfony.com/doc/current/book/routing.html#book-routing-conditions |
So, would it be possible to leverage the EL instance part of the routing layer to negotiate the right controller/action now? I am a bit lost, but it looks like Symfony 2.4 now relies on the |
Essentially the approach here is to register a listener after the core
RouterListener
that tries to map the controller based on the media type. The media type map is configured inside the route.Example route:
Todos:
_controller_map
defined (instead one can just usetrue
to enable the feature)@newLoki: if you have time to work on any of the above items please let me know via a comment in this ticket.