Skip to content
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

Add an option to chose order of match route (3.x) #110

Closed
gsouf opened this issue Oct 15, 2015 · 6 comments
Closed

Add an option to chose order of match route (3.x) #110

gsouf opened this issue Oct 15, 2015 · 6 comments

Comments

@gsouf
Copy link

gsouf commented Oct 15, 2015

Right now route matcher matches routes in FIFO order.

For some reasons you might want the matcher to match in FILO order.

I propose to add a way for the matcher to know how he should process. At a first sight, it would be very easy to implement just by reversing this loop:

foreach ($this->map as $name => $proto) {

That could look like:

   $routerContainer->getMatcher()->setReverseMatchOrder(true);

What's your opinion?

@gsouf
Copy link
Author

gsouf commented Oct 26, 2015

ping @harikt @pmjones

@harikt
Copy link
Member

harikt commented Oct 26, 2015

@gsouf this is possible. Not sure whether that is really need though. Send a PR if you are really in need for it. Not sure what @pmjones think about this.

@gsouf
Copy link
Author

gsouf commented Oct 26, 2015

@harikt before writing any PR I want to know your opinion, that kind of new feature needs to be discussed i think

@pmjones
Copy link
Member

pmjones commented Dec 1, 2015

After thinking about this for some time, I think the answer is "it's not needed." I don't think any router anywhere does LIFO matching, and honestly I can't imagine needing it. If you want to write up a use case, we can re-open the issue and discuss it some more.

@pmjones pmjones closed this as completed Dec 1, 2015
@gsouf
Copy link
Author

gsouf commented Dec 2, 2015

@pmjones I actually have a use case that can be discussed. This case is a bit edgy indeed, in a real web application that would probably never be useful. But in my case it is. Here is the case:

I use the aura router to unit test API client with PSR-7 requests
In the router I have some default routes. Let's say:

$map->get("route1", "/route1", [...]);
$map->get("route2", "/route2", [...]);

Latter in the application some route may be overwritten by the user:

$map->get(null, "/route1", [...]); // This will never match because the previous /route1 matches before

An obvious workarround is to store everything in an associative array that will keep only 1 trace of each route , then create the router on demand but it requires to also store all the thing that are unique in the matching (uri, method, ...) also the flexibility of route grouping, etc...

An other workarround would be to write my own router class that extends the original and that provides reversed routing. But if this feature can be shared, it's better.

@pmjones
Copy link
Member

pmjones commented Dec 2, 2015

Overwriting a route later in the setup process does not mean changing to LIFO will work as expected. What you want in that case is to replace the existing route, not to check the routes in reverse order.

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

No branches or pull requests

3 participants