Let's say we have 2 routes defined like this:
$this->app->get('/user/search', self::foo($app));
$this->app->get('/user/{id}', self::bar($app));
I would have expected /user/search
to be matched against before /user/{id}
. However, it's the reverse order.
In the documentation, I noticed the following:
Since you can add many routes as you need using the add() method, the order in which routes are added indicate their relevance, latest routes added have more relevance than first added. Internally, all defined routes are traversed in reverse order until Phalcon\Mvc\Router finds the one that matches the given URI and processes it, while ignoring the rest.
Documenting routes in this fashion seems counterintuitive. Every framework I've ever used has parsed routes top/down, which is also the way in which we read code. I'm curious what the technical reason behind this decision was. I'm also curious if the Phalcon team is open to exposing an optional way to set the preferred route priority to be top/down versus bottom/up.
Any feedback would be appreciated.