nikic / FastRoute

Fast request router for PHP
Other
5.1k stars 445 forks source link

Cancelling (continuing past) a matched route #107

Closed matthew-dean closed 7 years ago

matthew-dean commented 8 years ago

In Express and other routing libraries, it's a common pattern to match a route, and then decide in the associated function that the route should no longer matched, and therefore the router should continue to check the remaining routes for a match.

Slim 2 used to support this functionality, but since adopting FastRoute, it doesn't seem to. (See: https://github.com/slimphp/Slim/issues/1912) Is there a way to do this with FastRoute, and, if not, could this functionality be added? Basically, imagine it like a "continue" statement for a loop; e.g. skip this iteration and go on to the next. (An imperfect metaphor but illustrating a parallel functionality.)

nimmneun commented 8 years ago

From how I understand FastRoute ... as of now it does not evaluate any action associated with a route, since its not its responsibility.

nikic commented 7 years ago

I don't think there is any good way to support this kind of functionality in FastRoute due to the way it performs matching. Routes are matched in batches, so this pretty much dictates that we cannot go past the first match in one batch. Of course one could fall back to matching individual routes after a cancelled first match, but this would make the implementation significantly more complicated. Additionally we have the problem that FastRoute does not interact with the route callback in any way -- it only returns it and the callee then decides what to do with it. As such, this kind of cancelling functionality would also require a different API than we currently have.

As such I don't think this is possible, so closing this issue.