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
Comments
|
@harikt before writing any PR I want to know your opinion, that kind of new feature needs to be discussed i think |
|
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 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 $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 beforeAn 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. |
|
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. |
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:
Aura.Router/src/Matcher.php
Line 117 in 57a8066
That could look like:
What's your opinion?
The text was updated successfully, but these errors were encountered: