diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-13 19:28:20 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-12-23 09:50:42 +0100 |
commit | f1951237653ffbbf7fd75f815f401783658cec5e (patch) | |
tree | 360c85776f363e4b4447272c96c06d25863138d1 /lib/private/route/router.php | |
parent | d8f04f5a97e77bf5fb84b05ddd9b3a476fecfb7c (diff) | |
download | nextcloud-server-f1951237653ffbbf7fd75f815f401783658cec5e.tar.gz nextcloud-server-f1951237653ffbbf7fd75f815f401783658cec5e.zip |
Intelligent container
* resolves dependencies by type hint or variable name
* simpler route.php
* implementation of https://github.com/owncloud/core/issues/12829
Generates and injects parameters automatically. You can now build full classes like
$c->query('MyClassName')
without having to register it as a service. The resolved object's instance will be saved by using registerService. If a constructor parameter is not type hinted, the parameter name will be taken.
Therefore the following two implementations are identical:
class Class1 { function __construct(MyClassName $class)
class Class1 { function __construct($MyClassName)
This makes it possible to also inject primitive values such as strings, arrays etc.
In addition if the query could not be resolved, a `QueryException` is now thrown
Routes can now be returned as an array from `routes.php` and an `appinfo/application.php` is optional
Old commit messages:
make it possible to return the routes instead of having to intialize the application
try to get the controller by convention
add first implementation of automatic resolve
add another test just to be sure
store the resolved object
more tests
add phpdoc to public app.php method
use the same variable for the public app.php method
deprecate old methods and add services for public interfaces
deprecated getServer method
disallow private api injection for apps other than core or settings (settings should be an app goddamnit :D)
register userid because its such an often used variable
fix indention and leading slash
use test namespace
add deprecation reasons, remove private api usage checks and remove deprecation from getServer()
add additional public interfaces
add public interface for rootfolder
fix syntax error
remove deprecation from methods where no alternative is there yet
remove deprecated from method which has no alternative
add timezone public service for #12881
add another deprecation hint
move deprecation into separate branch
remove dead comment
first try to get the namespace from the info.xml, if it does not exist, just uppercase the first letter
also trim the namespace name
add an interface for timefactory
move timefactory to public and add icontrollermethodreflector
keep core interface
fix copyright date in headers
Diffstat (limited to 'lib/private/route/router.php')
-rw-r--r-- | lib/private/route/router.php | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/private/route/router.php b/lib/private/route/router.php index 5d6f621dc38..3559b841926 100644 --- a/lib/private/route/router.php +++ b/lib/private/route/router.php @@ -9,6 +9,7 @@ namespace OC\Route; use OCP\Route\IRouter; +use OCP\AppFramework\App; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RequestContext; @@ -129,7 +130,7 @@ class Router implements IRouter { if (!isset($this->loadedApps[$app])) { $this->loadedApps[$app] = true; $this->useCollection($app); - $this->requireRouteFile($file); + $this->requireRouteFile($file, $app); $collection = $this->getCollection($app); $collection->addPrefix('/apps/' . $app); $this->root->addCollection($collection); @@ -283,10 +284,39 @@ class Router implements IRouter { /** * To isolate the variable scope used inside the $file it is required in it's own method - * @param string $file + * @param string $file the route file location to include + * @param string $appName */ - private function requireRouteFile($file) { - require_once $file; + private function requireRouteFile($file, $appName) { + $this->setupRoutes(include_once $file, $appName); } + + /** + * If a routes.php file returns an array, try to set up the application and + * register the routes for the app. The application class will be chosen by + * camelcasing the appname, e.g.: my_app will be turned into + * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default + * App will be intialized. This makes it optional to ship an + * appinfo/application.php by using the built in query resolver + * @param array $routes the application routes + * @param string $appName the name of the app. + */ + private function setupRoutes($routes, $appName) { + if (is_array($routes)) { + $appNameSpace = App::buildAppNamespace($appName); + + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; + + if (class_exists($applicationClassName)) { + $application = new $applicationClassName(); + } else { + $application = new App($appName); + } + + $application->registerRoutes($this, $routes); + } + } + + } |