Macaw - A Simple PHP Router
github.com
github.com
fastcgi_param HTTPS $https if_not_empty;
Also, the 404 route, should be able to be defined as a custom function: Macaw::fourofour(function() {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
header("Status: 404 Not Found");
});idk. this mixes up routing and api building, right? What people currently use most to build their api (mostly afterwards) is: http://docs.guzzlephp.org/en/latest/
btw. here's a nice and new php framework I've just recently found: http://www.cygniteframework.com/2013/07/quickstart.html
For a second I thought someone had coded an IP router in PHP. Which would be a really interesting thing to see, if not particularly practical.
# Static attributes and methods. Are they really needed? They are difficult to test and predict, specially the public attributes.
# The "echo"s on routes. Since every route is a method (encapsulated by one), this behavior could be easily avoided (easier to test and control). You are already using callables, you can easily test (and run) matching routes to execute any callable until a stream is given (on Respect/Rest we learned what a powerful feature it is).
# Lack of tests. Although low LOC, there is much happening, specially on the "dispatch" method (it would be awesome to know through tests what the If's/Else's actually do and prevent).
# Why (as mentioned before) the error header do not provide a proper HTTP header!? It would also be nice to provide two different error routes: one for client errors (404: not found, forbidden) and another to server errors (HTTP/1.1 500 Server Error).
A suggestion (we've been talking a lot on Respect/Rest) is to implement the URI Template (RFC 6570) for matching routes and hydration of parameters (something macaw lacks but i like using the PHP way of $_GET, $_POST and filter_input()). With a component dealing nicely with URI Templates many projects would benefit from it.
I'm using it to make a JSON backend API and it works great.
Silex and other microframeworks are great for these.
https://github.com/GetParrot/Parrot
so I think he just likes parrots and the name is coincidence.
For precisely this reason, I wrote a PHP router like this called Marg - http://github.com/vaidik/marg. Used it for 3 projects and I love the way I can keep things simple and sane. And that's why I appreciate this project as well.
Great to see sane projects like these in the PHP community.
Not as bad as using extract() though. Yes i'm looking at you Wordpress.
nice job on creating a really damn simple interface.
[1] https://github.com/jmathai/epiphany
[2] https://github.com/jmathai/epiphany/blob/master/examples/reg...
[3] https://trovebox.com/blog/building-trovebox-entirely-using-o...
[0]: https://github.com/jmathai/epiphany/blob/master/src/EpiRoute...
[1]: http://en.wikipedia.org/wiki/Shunting-yard_algorithm
[2]: http://blog.bigbinary.com/2013/01/29/journey-into-rails-rout...
if I had any suggestions at all though it would be to have the 404 route actually return the 404 header (or have a way to specify headers with routes), and also have it handle https.
Probably, all a bare minimum viable url router should do is display some content based on a url or fail to an error code. I would post my own experiments with building a url router that deals with everything (because I tried it) but the end results were objectively worse than what's already been posted here... i've found that it helps to have the router, and whatever process handles rendering the document as a whole (including headers and caching) be completely separate.