diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-03-24 14:55:03 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-03-24 14:55:03 +0100 |
commit | 0d0aac6fffb2da47054ed19eae835aa7d9904692 (patch) | |
tree | ad55d9471967736a86eb79e37e47d669d07fd3ce | |
parent | 4c8a83e82fe4dfe5b83e09194060ecbf44f44791 (diff) | |
download | nextcloud-server-0d0aac6fffb2da47054ed19eae835aa7d9904692.tar.gz nextcloud-server-0d0aac6fffb2da47054ed19eae835aa7d9904692.zip |
Load the routes when matching or generating a route instead of when creating the router
-rw-r--r-- | lib/private/route/router.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 16 | ||||
-rw-r--r-- | lib/public/route/irouter.php | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/lib/private/route/router.php b/lib/private/route/router.php index 60ba5878401..806bbf51abf 100644 --- a/lib/private/route/router.php +++ b/lib/private/route/router.php @@ -158,6 +158,7 @@ class Router implements IRouter { * @throws \Exception */ public function match($url) { + $this->loadRoutes(); $matcher = new UrlMatcher($this->root, $this->context); $parameters = $matcher->match($url); if (isset($parameters['action'])) { @@ -196,6 +197,7 @@ class Router implements IRouter { * @return string */ public function generate($name, $parameters = array(), $absolute = false) { + $this->loadRoutes(); return $this->getGenerator()->generate($name, $parameters, $absolute); } diff --git a/lib/private/server.php b/lib/private/server.php index 8c9ea39c562..5c83f3ef495 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -159,7 +159,15 @@ class Server extends SimpleContainer implements IServerContainer { return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); }); $this->registerService('Router', function ($c){ - $router = new \OC\Route\Router(); + /** + * @var Server $c + */ + $cacheFactory = $c->getMemCacheFactory(); + if ($cacheFactory->isAvailable()) { + $router = new \OC\Route\CachingRouter($cacheFactory->create('route')); + } else { + $router = new \OC\Route\Router(); + } return $router; }); } @@ -327,7 +335,7 @@ class Server extends SimpleContainer implements IServerContainer { /** * Returns an \OCP\CacheFactory instance * - * @return \OCP\CacheFactory + * @return \OCP\ICacheFactory */ function getMemCacheFactory() { return $this->query('MemCacheFactory'); @@ -375,8 +383,6 @@ class Server extends SimpleContainer implements IServerContainer { * @return \OCP\Route\IRouter */ function getRouter(){ - $router = $this->query('Router'); - $router->loadRoutes(); - return $router; + return $this->query('Router'); } } diff --git a/lib/public/route/irouter.php b/lib/public/route/irouter.php index d6b0750ba6f..df397bc8758 100644 --- a/lib/public/route/irouter.php +++ b/lib/public/route/irouter.php @@ -10,8 +10,6 @@ namespace OCP\Route; interface IRouter { - public function __construct(); - /** * Get the files to load the routes from * |