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

reverse routing #139

Closed
jdv145 opened this issue Aug 4, 2017 · 2 comments · Fixed by #277
Closed

reverse routing #139

jdv145 opened this issue Aug 4, 2017 · 2 comments · Fixed by #277

Comments

@jdv145
Copy link

jdv145 commented Aug 4, 2017

I'm not an expert on git-etiquette , but i hope this is the right place for a remark/suggestion or 2.

Basically i made a reverse router myself, just using some regexps and string replacements (i love regexp's power, but it doesn't always help to create the easiest to understand code). It worked but felt a bit cumbersome.

I think the routing part of my system is very important, so i gave it a second attempt where i created a full parse-tree and just traveled through it doing as i pleased (checking, var injection, whatever). Afterwards the tree can "rebuild" itself again and it works fine. Also one of the reasons to build a tree is to resolve ambiguity of optional parameters (i previously was not aware of the (very wise) restrictions on optionals, so the tree works for way more then is allowed in fastroute ).

i recently found out there is a suggestion how to reverse routes based on fastroute internals which i of course prefer.

I'm referring to: this

  • I was wondering why something like the suggestion is not implemented in fastroute, since it seems to work fine. Where any person is routing, sooner or later an urls needs to be generated.

  • Using the linked suggestion as a base for my own implementation, i'm a bit hesitant to blindly trust the output from RouteParser\Std for future versions to come. Any feedback on this? I did look into the parser of course but i only superficially understand its inner workings.

(- just out of curiosity, why not use a parse tree, and work with regexps? Is this bc its more work to code ? )

@jdv145 jdv145 changed the title routing reverse routing Aug 4, 2017
@nikic
Copy link
Owner

nikic commented Sep 17, 2017

I was wondering why something like the suggestion is not implemented in fastroute, since it seems to work fine. Where any person is routing, sooner or later an urls needs to be generated.

I agree that it would be nice to include this functionality, the problem for me is that I don't see a good way to integrate it into the current architecture. Among other things a) the dispatcher no longer has the necessary information to do this and b) I think that reverse routing requires support for "named routes" as a prerequisite, something we don't have either.

Suggestions on how to integrate this (API wise) would be welcome.

Using the linked suggestion as a base for my own implementation, i'm a bit hesitant to blindly trust the output from RouteParser\Std for future versions to come. Any feedback on this? I did look into the parser of course but i only superficially understand its inner workings.

This library follows semver, and the parser is part of the public API, so the format is not going to change (at least in 1.x).

(- just out of curiosity, why not use a parse tree, and work with regexps? Is this bc its more work to code ? )

Mainly because at the time the route format was rather simple and a parser seemed like overkill. Maybe that's not the case anymore ^^

@burzum
Copy link
Contributor

burzum commented Aug 14, 2018

@nikic I would like to see named routes as well and reverse routing.

https://github.com/nikic/FastRoute/blob/master/src/Route.php

Wouldn't it be possible to simply add a 5th arg here $name? A reverse route class could simply take the collection and pick a route by it's name and reverse it.

By the way, why is the returned structure unspecified? From what I've seen it's basically always an array and you identify the kind of result by the first key. https://github.com/nikic/FastRoute/blob/master/src/DataGenerator.php

Wouldn't it make sure sense to return an object with an interface? Like RouteNotFoundResult, FoundResult and NotAllowedResult implementing RoutingResultInterface? If you implement array access this could work in a BC fashion without breaking stuff.

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

Successfully merging a pull request may close this issue.

3 participants