-
Notifications
You must be signed in to change notification settings - Fork 444
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
Backwards-compatible reverse routing #270
Conversation
1a25cdd
to
dd4d0e9
Compare
@pmjones thanks for working on this feature. I'll review it more thoroughly over the week. On a high level, the design diverges a bit from what I had in mind (though I was thinking about v2). Since we can't guarantee that the route handler points to a class name, I thought on leveraging #269 for providing identifiers. When it comes to the creation of dispatcher/generator, I was drafting something that moves away from the usage of hash maps to configure the process. I'm working on documenting and reducing the impact of BC-breaks in v2 and would prefer to focus on its release, instead of having v1.4 in between. I'll open new prs with my drafts over the next few days and we can discuss things further. |
Understood. I can imagine a string handler being used as the default name; although (depending on the design) an extended class might add that instead.
I look forward to it! (If you find that the time commitment becomes too great, maybe we can revisit this PR for the 1.x series.) |
@pmjones I'll add on that PR an alternative implementation for the reverse routing (based on extra parameters) - sorry about the delay, last week was a bit crazy... We should be good with v2 pretty soon. |
No rush on my part! Looking forward to seeing it. |
@lcobucci As a side note, I have incorporated this reverse-routing functionality along with some automated typecasting in CastRoute, as yet unreleased. Let me know if anything there looks like it would be suitable here -- I'd rather have stuff like that in FastRoute proper than in a "decorator" project. |
This PR implements backwards-compatible reverse routing (route generation). It passes all tests on PHP 5.6, but I have been unable to test all the way back to PHP 5.4 or on HHVM.
Existing calls to simpleDispatcher() and cachedDispatcher() continue to work as before, but will not get access to the new RouteGenerator object for reverse routing.
To get access to reverse routing, replace calls to simpleDispatcher()/cachedDispatcher() with calls to the new FastRoute container object to build both the Dispatcher and the RouteGenerator:
Now you can get the Dispatcher and Route Generator:
The RouteGenerator will only work with string handlers; the string handler value doubles as the route name. This means:
To generate a route, pass the string handler and the values to interpolate into the route. The RouteGenerator will build as many optional segments as it can; if an optional value is missing, generation is terminated and the existing URL segments are returned.
If this feature is not within the project scope, or if the implementation fails to meet project design goals, please let me know and I will retract or remedy.