Well after some discussion we reverted my latest change to router to 3.2.x which is supposed to take advantage of router prefix to process routes faster. We decided to postpone this change to 4.0.0 with more changes to router. There is a list what i propose:
- delete
Phalcon\Mvc\Router\Group, move necessary methods(like for example setPrefix, setPaths) to Phalcon\Mvc\Router and add Phalcon\Mvc\Router::merge so we can still have separated "route group" classes, just without duplicated/very similar code
- change
Phalcon\Mvc\Router::add so it will accept Phalcon\Mvc\Router\RouteInterface as first argument(keep old behavior too) or add separated method addRoute
- add factories
Route::get, Route::post, etc and Route::via to create route object
- separate routes into groups with prefixes, add method for getting routes only for certain prefix
- separate routes into groups with http methods, add methods for getting routes only for certain method
- instead of checking all routes no matter what prefix/method, get method from request, check correct group, and check prefix if url starts with it - this will improve performance much, when i will finish i will try to do some real case tests with AB
- additionally add separated class for storing all routes like
Phalcon\Mvc\Router\Collection and actual logic for adding routes will happen there, Phalcon\Mvc\Router will only call some methods
- the problem will be currently code like this:
$router->add("/products", "Products::get")->via(['POST', 'GET']);
The best will be just to throw some exception(just some flag in Route class which will be set after creating and adding it in Phalcon\Mvc\Router) when user will try to do via on this point - because otherwise we will need to do a lot of dirty stuff here(like add it to all method groups and then remove it from not selected method groups etc). So user will need to change his code to:
$router->add("/products", "Products::get", ['POST', 'GET']);
or
$router->add(Route::via('/products', 'Products::get', ['POST', 'GET']));
If someone is using Phalcon\Mvc\Router\Group the only change he will need to do is change extends Router\Group to extends Router and $router->mount to $router->merge.
@michanismus
Well after some discussion we reverted my latest change to router to 3.2.x which is supposed to take advantage of router prefix to process routes faster. We decided to postpone this change to 4.0.0 with more changes to router. There is a list what i propose:
Phalcon\Mvc\Router\Group, move necessary methods(like for examplesetPrefix,setPaths) toPhalcon\Mvc\Routerand addPhalcon\Mvc\Router::mergeso we can still have separated "route group" classes, just without duplicated/very similar codePhalcon\Mvc\Router::addso it will acceptPhalcon\Mvc\Router\RouteInterfaceas first argument(keep old behavior too) or add separated methodaddRouteRoute::get,Route::post, etc andRoute::viato create route objectPhalcon\Mvc\Router\Collectionand actual logic for adding routes will happen there,Phalcon\Mvc\Routerwill only call some methodsThe best will be just to throw some exception(just some flag in Route class which will be set after creating and adding it in
Phalcon\Mvc\Router) when user will try to do via on this point - because otherwise we will need to do a lot of dirty stuff here(like add it to all method groups and then remove it from not selected method groups etc). So user will need to change his code to:or
If someone is using
Phalcon\Mvc\Router\Groupthe only change he will need to do is changeextends Router\Grouptoextends Routerand$router->mountto$router->merge.@michanismus