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

[Routing] Get all matched routes (add method which not stops on the first matched candidate) #10113

Closed
Koc opened this Issue Jan 23, 2014 · 8 comments

Comments

Projects
None yet
5 participants
@Koc
Contributor

Koc commented Jan 23, 2014

I'm using Symfony-CMF RoutingBundle with NestedMatcher http://symfony.com/doc/master/cmf/components/routing/nested_matcher.html . And for the route provider / route filter I should get all matched routes. Now it is not possible, I've copypasted bunch of code from UrlMatcher class.

@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Jan 23, 2014

Member

I think that if you use same logic than the UrlMatcher in your RouteProvider implementation, you are doing things wrong. The documentation explains that the UrlMatcher logic is already used in the FinalMatcherInterface implementation by default, so it means you are putting some logic at the wrong layer.

I don't think it makes sense to have a method to get all matched routes, because there is always a single matched route in the Routing component.
Expecting a matcher to be able to return several candidates severely restricts what a matcher can do (it would become impossible to implement an ApacheUrlMatcher for instance)

Member

stof commented Jan 23, 2014

I think that if you use same logic than the UrlMatcher in your RouteProvider implementation, you are doing things wrong. The documentation explains that the UrlMatcher logic is already used in the FinalMatcherInterface implementation by default, so it means you are putting some logic at the wrong layer.

I don't think it makes sense to have a method to get all matched routes, because there is always a single matched route in the Routing component.
Expecting a matcher to be able to return several candidates severely restricts what a matcher can do (it would become impossible to implement an ApacheUrlMatcher for instance)

@Koc

This comment has been minimized.

Show comment
Hide comment
@Koc

Koc Jan 23, 2014

Contributor

As I know ApacheUrlMatcher is near deprecation.

Yes, it looks like I do it wrong, but let me explain my problem much detailed. Url consists of some combinations of slugs: company_slug, category_slug, parameters_slug, city_slug. Some parameter can be in different places - it would match different route.

http://www.metalloprokat.dev/sort/armatura/ # sort/armatura - category_slug
http://msk.metalloprokat.dev/sort/armatura/ # msk - city_slug, sort/armatura - category_slug
http://vik-profi.metalloprokat.dev/ # vik-profi - company_slug
http://vik-profi.metalloprokat.dev/sort/armatura/
http://www.metalloprokat.dev/vik-profi/
http://www.metalloprokat.dev/vik-profi/sort/armatura/ # vik-profi - company_slug, sort/armatura - category_slug
http://www.metalloprokat.dev/vik-profi/sort/armatura/ab_cd/ef_g # vik-profi - company_slug, sort/armatura - category_slug, ab_cd/ef_g - parameters_slug combination
http://www.metalloprokat.dev/spros/sort/armatura/ # sort/armatura - category_slug
http://msk.metalloprokat.dev/spros/sort/armatura/ # msk - city slug, sort/armatura - category_slug

So I don't know what route matched. I take all matched routes and for each load categories/cities/parameters/companies by matched slugs.

Contributor

Koc commented Jan 23, 2014

As I know ApacheUrlMatcher is near deprecation.

Yes, it looks like I do it wrong, but let me explain my problem much detailed. Url consists of some combinations of slugs: company_slug, category_slug, parameters_slug, city_slug. Some parameter can be in different places - it would match different route.

http://www.metalloprokat.dev/sort/armatura/ # sort/armatura - category_slug
http://msk.metalloprokat.dev/sort/armatura/ # msk - city_slug, sort/armatura - category_slug
http://vik-profi.metalloprokat.dev/ # vik-profi - company_slug
http://vik-profi.metalloprokat.dev/sort/armatura/
http://www.metalloprokat.dev/vik-profi/
http://www.metalloprokat.dev/vik-profi/sort/armatura/ # vik-profi - company_slug, sort/armatura - category_slug
http://www.metalloprokat.dev/vik-profi/sort/armatura/ab_cd/ef_g # vik-profi - company_slug, sort/armatura - category_slug, ab_cd/ef_g - parameters_slug combination
http://www.metalloprokat.dev/spros/sort/armatura/ # sort/armatura - category_slug
http://msk.metalloprokat.dev/spros/sort/armatura/ # msk - city slug, sort/armatura - category_slug

So I don't know what route matched. I take all matched routes and for each load categories/cities/parameters/companies by matched slugs.

@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Jan 23, 2014

Member

I took the ApacheUrlMatcher as an example for which it would fail. It does not mean it would be the only one.

Regarding your use case, this seems a big weird. what happens if I create a category named vik-profi ? would http://www.metalloprokat.dev/vik-profi/ match it as category slug (first case) or as company slug (fifth case) ? Your routing is becoming ambiguous.
I think for such case, the way urls are built should probably be questioned.

Member

stof commented Jan 23, 2014

I took the ApacheUrlMatcher as an example for which it would fail. It does not mean it would be the only one.

Regarding your use case, this seems a big weird. what happens if I create a category named vik-profi ? would http://www.metalloprokat.dev/vik-profi/ match it as category slug (first case) or as company slug (fifth case) ? Your routing is becoming ambiguous.
I think for such case, the way urls are built should probably be questioned.

@Koc

This comment has been minimized.

Show comment
Hide comment
@Koc

Koc Jan 23, 2014

Contributor

Categories created by site moderator. Users cann't create companies with reserved keywords or keywords used for categories. So this case impossible in our system. It seems like social network: any url can be user profile or community page or event (meet). Also users cann't register company with slug which used for city.

Contributor

Koc commented Jan 23, 2014

Categories created by site moderator. Users cann't create companies with reserved keywords or keywords used for categories. So this case impossible in our system. It seems like social network: any url can be user profile or community page or event (meet). Also users cann't register company with slug which used for city.

@Koc

This comment has been minimized.

Show comment
Hide comment
@Koc

Koc Jan 23, 2014

Contributor

BTW this is possible requirements. I've realized described functionality today using copy-paste from matcher. Other bad thing: it looks like currently my implementation does not use codegenerated cache, so I've created this tocket.

Contributor

Koc commented Jan 23, 2014

BTW this is possible requirements. I've realized described functionality today using copy-paste from matcher. Other bad thing: it looks like currently my implementation does not use codegenerated cache, so I've created this tocket.

@Koc

This comment has been minimized.

Show comment
Hide comment
@Koc

Koc Jan 25, 2014

Contributor

Also this may be useful for debug purposes: detect possible intersection of routes.

Contributor

Koc commented Jan 25, 2014

Also this may be useful for debug purposes: detect possible intersection of routes.

@TomasVotruba

This comment has been minimized.

Show comment
Hide comment
@TomasVotruba

TomasVotruba Feb 29, 2016

Contributor

@Koc Could you send PR for this feature?

Contributor

TomasVotruba commented Feb 29, 2016

@Koc Could you send PR for this feature?

@nicolas-grekas

This comment has been minimized.

Show comment
Hide comment
@nicolas-grekas

nicolas-grekas Feb 23, 2018

Member

I'm closing here because the issue is old and no implementation has been provided yet.
Feel free to submit a PR of course.

Member

nicolas-grekas commented Feb 23, 2018

I'm closing here because the issue is old and no implementation has been provided yet.
Feel free to submit a PR of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment