-
Notifications
You must be signed in to change notification settings - Fork 326
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
[WIP] Remove global routing #656
Conversation
`static $_routes` has been removed, as well as code that depends on it. Tests are adjusted accordingly.
Ah, by the way, removing global routes makes HMVC |
So I was wondering if you want me to continue working on this PR. An implementation of loading the routes from config would be: public static function load()
{
$config = Kohana::$config->load('routes');
$routes = array();
foreach ($config as $name => $def)
{
$r = new Route(Arr::get($def, 'url'), Arr::get($def, 'regex'));
$r->defaults(Arr::get($def, 'defaults'));
if ($filter = Arr::get($def, 'filter')) {
$r->filter($filter);
}
$routes[$name] = $r;
}
// return
return $routes;
} This could go in a separate class As a separate note, upgrading from |
If you are too worried about the HMVC calls complexity, we can remake Request to load the routes, but this time from config, during its during construction, when a |
@enov this looks good but what I'm missing is the guide on how routing will work from here on. Could you please update the guide and also add a upgrade 3.3 to 3.4 note? |
Thanks @rjd22. I will add the guide and an upgrade note once it is complete, and there is consensus where it is heading. Could you also confirm if you are in favor of config based routing? i.e to have return [
'default' => [
'uri' => '(<controller>(/<action>(/<id>)))',
'defaults' => [
'controller' => 'welcome',
'action' => 'index',
],
],
]; |
@enov I don't have a problem with config based routing. As long as you can also do it by injecting route objects into the router. |
@enov does this also remove the ability to do reverse routing (eg with I'm less in favour of config-based routing, I think routes provided by modules shouldn't be automatically included but should be explicitly required by the application. Otherwise it can get annoying figuring out what urls are actually in use/valid/conflicting. So a module could define a routes.php with defaults but the application should include that file rather than it happen automatically. I think. |
It does not remove the ability of reverse routing, as public function get($name)
{
$routes = Route::load();
return $routes[$name];
} If we do not bring back |
There should be an additional return [
'module.route' => [
'enabled' => TRUE,
],
] Then you can have all your application routes visible in your config. The rules of config files play well in this case, as values are merged. I also suggest to have an |
Not pushing this hard on anybody, though I think it is to the right direction. Some frameworks are config based, while others define routes via HTTP-verbs-like-API methods. In all cases, this needs some time to be fully implemented. #524 complains about:
ATM, modules are loaded top-to-bottom. This became a more explicit issue in v3.4, when @lenton rendered the core to become itself a standard module. We can leave this as a known issue, and go ahead with the general feeling to release Kohana 3.4. |
Closing this, as it might not go to 3.4, and can be scheduled for later. |
This is a tentative PR to remove global routing, i.e. the use of
Route::set
, while relying only on injecting the routes when constructingRequest
s or overriding injected ones viaset_routes
.This will solve #524 as well as go forward with #499.
I am also in favor of config routing. I think we had routing based on config files in Kohana 2? But never used Kohana 2 so I am not sure.
I am awaiting your comments regarding this.
Cheers!