-
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
Load controllers with FQCN. #578
Conversation
I think it is ok for full BC with the old routing system. For consistancy between the two methods, however, I would have prefered the notion of the prefix as well as the directory to go away. Not sure though how it can be done. |
Maybe it should rather check for existance of So |
@kemo a namespaceless class should also begin with a \ like \Kohana. Because it's still in a name space only the global one. |
Yes but as things stand right now, those won't support directories (unless written without the initial |
@rjd22 thanks for this, my thoughts:
|
Actually, just a thought - we could satisfy several of these cases and keep BC with a If Otherwise, build a class name by passing the format through strtr: # /welcome => Controller_Welcome as now
Route::set('default', '<controller>/<action>')
->defaults(array());
# /welcome => Controller_Other_Welcome as now
Route::set('default', '<controller>/<action>')
->defaults(array(
'directory' => 'Other'
));
# /welcome => \My\Controller\Welcome
Route::set('default', '<controller>/<action>')
->defaults(array(
'controller_format' => '\My\Controller\:controller'
));
# /welcome => \My\Whatever\WelcomeController
Route::set('default', '<controller>/<action>')
->defaults(array(
'controller_format' => '\My\Whatever\:controllerController'
));
# /directory/welcome => \My\Whatever\Directory_WelcomeController - yuk, but supported
Route::set('default', '<directory>/<controller>/<action>')
->defaults(array(
'controller_format' => '\My\Whatever\:directory:controllerController'
)); That would be fully BC, but would also support url-based controllers in namespaces with any (or no) prefix/suffix/whatever and directories if you really need them. Thoughts? |
@acoulton This will add another layer of complexity in the route I would like to see the What if we introduce the Basically we use If we want to drop Not tested though, but should be fully BC. # /welcome => Controller_Welcome (BC)
Route::set('default', '<controller>/<action>')
->defaults(array())
# /welcome => Foo_Controller_Welcome (BC)
Route::set('default', '<controller>/<action>')
->defaults(array(
'directory' => 'Foo'
))
# /welcome => Controller_MyWelcome (BC)
Route::set('default', 'welcome/<action>')
->defaults(array(
'controller' => 'MyWelcome'
))
# /welcome => \Acme\Module\Ctnl\Welcome
Route::set('default', '<controller>/<action>')
->defaults(array(
'namespace' =>'\Acme\Module\Ctnl'
))
# /welcome => \Acme\Module\Ctnl\MyWelcome
# $namespace !== NULL
Route::set('default', 'welcome/<action>')
->defaults(array(
'namespace' => '\Acme\Module\Ctnl',
'controller' => 'MyWelcome
))
# /welcome => \Acme\Module\Ctnl\MyWelcome
# strpos($controller, '\\')
Route::set('default', 'welcome/<action>')
->defaults(array(
'controller' => '\Acme\Module\Ctnl\MyWelcome'
)) |
Shouldn't we just keep things simple for now? More complex implementations can always be implemented if there is a need for it. I will move the check to the router and add documentation for it. |
@rjd22 sorry, you're right - let's just start by supporting explicit FQCN in the definition. As a side-effect that might encourage more people to use at least a route per controller, which would be no bad thing... And we can add more complex implementations later if we need them. Obviously there's also scope for people to do that with filters now. I think let's merge this once you've done the test/docs/moved the exception. @loonies that would at least satisfy your "get rid of the prefix", "drop directory" and "keep it simple"? |
@acoulton sorry I haven't made the time to split this up. I will try to do so next weekend. Just giving a heads up. |
@rjd22 no worries, I hadn't made the time to even reply :) |
Keep it simple as it is currently, without We need the |
@acoulton After looking I think the check is on the right spot. The router does not care about the directory or the FQCN the Kohana internals do because it has to locate the file. Maybe we should change the message the Route class just doesn't have a appropriate spot for it. |
@rjd22 I think objects should be responsible for validating their own state. If it's not valid for a Route to have both a FQCN controller param and a directory param, then it should refuse to accept them. Absolutely Route shouldn't care about file location, but If anything, the misplaced logic is where Kohana request client assembles the class name, after the Route object separately handles From a pragmatic point of view, what's more useful if you define a route with an FQCN and a directory (classname prefix):
|
The problem is that we're talking about default values. So we won't be able to check in route set. The only way is the check if both directory and a FQCN is set when calling defaults(). The a exception will be thrown when setting the routes. Maybe that is better? |
@rjd22 looks great, but shouldn't there also be a test that |
Add documentation on how the use FQCN routing Moved check for FQCN and directory and added tests Forgot some of the test description
3026238
to
79615fb
Compare
…ller class Adds tests to cover the new FQCN controller class mapping as well as legacy behaviour with and without directory prefixes.
@rjd22 I've added tests, what do you think? |
Loons great. |
Fixes part of #571
It's BC and works by the following syntax:
The syntax won't work but I think that when using FQCN you should not use variable controller parameters.
@acoulton or @enov can you please review if this is okay?