Load the routes when matching or generating a route instead of when creating the router

This commit is contained in:
Robin Appelman 2014-03-24 14:55:03 +01:00
parent 4c8a83e82f
commit 0d0aac6fff
3 changed files with 13 additions and 7 deletions

View File

@ -158,6 +158,7 @@ class Router implements IRouter {
* @throws \Exception * @throws \Exception
*/ */
public function match($url) { public function match($url) {
$this->loadRoutes();
$matcher = new UrlMatcher($this->root, $this->context); $matcher = new UrlMatcher($this->root, $this->context);
$parameters = $matcher->match($url); $parameters = $matcher->match($url);
if (isset($parameters['action'])) { if (isset($parameters['action'])) {
@ -196,6 +197,7 @@ class Router implements IRouter {
* @return string * @return string
*/ */
public function generate($name, $parameters = array(), $absolute = false) { public function generate($name, $parameters = array(), $absolute = false) {
$this->loadRoutes();
return $this->getGenerator()->generate($name, $parameters, $absolute); return $this->getGenerator()->generate($name, $parameters, $absolute);
} }

View File

@ -159,7 +159,15 @@ class Server extends SimpleContainer implements IServerContainer {
return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
}); });
$this->registerService('Router', function ($c){ $this->registerService('Router', function ($c){
/**
* @var Server $c
*/
$cacheFactory = $c->getMemCacheFactory();
if ($cacheFactory->isAvailable()) {
$router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
} else {
$router = new \OC\Route\Router(); $router = new \OC\Route\Router();
}
return $router; return $router;
}); });
} }
@ -327,7 +335,7 @@ class Server extends SimpleContainer implements IServerContainer {
/** /**
* Returns an \OCP\CacheFactory instance * Returns an \OCP\CacheFactory instance
* *
* @return \OCP\CacheFactory * @return \OCP\ICacheFactory
*/ */
function getMemCacheFactory() { function getMemCacheFactory() {
return $this->query('MemCacheFactory'); return $this->query('MemCacheFactory');
@ -375,8 +383,6 @@ class Server extends SimpleContainer implements IServerContainer {
* @return \OCP\Route\IRouter * @return \OCP\Route\IRouter
*/ */
function getRouter(){ function getRouter(){
$router = $this->query('Router'); return $this->query('Router');
$router->loadRoutes();
return $router;
} }
} }

View File

@ -10,8 +10,6 @@ namespace OCP\Route;
interface IRouter { interface IRouter {
public function __construct();
/** /**
* Get the files to load the routes from * Get the files to load the routes from
* *