summaryrefslogtreecommitdiffstats
path: root/lib/private/route
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-03-24 15:41:46 +0100
committerRobin Appelman <icewind@owncloud.com>2014-03-24 15:41:46 +0100
commitf17674fef281da097838c22c71e14698f842a2db (patch)
treed7567415739b94853c7fdcf7bb89370dad7e55bc /lib/private/route
parent0d0aac6fffb2da47054ed19eae835aa7d9904692 (diff)
downloadnextcloud-server-f17674fef281da097838c22c71e14698f842a2db.tar.gz
nextcloud-server-f17674fef281da097838c22c71e14698f842a2db.zip
Only load routes from the apps we need
Diffstat (limited to 'lib/private/route')
-rw-r--r--lib/private/route/router.php50
1 files changed, 37 insertions, 13 deletions
diff --git a/lib/private/route/router.php b/lib/private/route/router.php
index 806bbf51abf..28c27b601c1 100644
--- a/lib/private/route/router.php
+++ b/lib/private/route/router.php
@@ -47,6 +47,8 @@ class Router implements IRouter {
protected $loaded = false;
+ protected $loadedApps = array();
+
public function __construct() {
$baseUrl = \OC_Helper::linkTo('', 'index.php');
if (!\OC::$CLI) {
@@ -93,27 +95,44 @@ class Router implements IRouter {
/**
* loads the api routes
*/
- public function loadRoutes() {
+ public function loadRoutes($app = null) {
if ($this->loaded) {
return;
}
- $this->loaded = true;
- foreach ($this->getRoutingFiles() as $app => $file) {
+ if (is_null($app)) {
+ $this->loaded = true;
+ $routingFiles = $this->getRoutingFiles();
+ } else {
+ if (isset($this->loadedApps[$app])) {
+ return;
+ }
+ $this->loadedApps[$app] = true;
+ $file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
+ if (file_exists($file)) {
+ $routingFiles = array($file);
+ } else {
+ $routingFiles = array();
+ }
+ }
+ foreach ($routingFiles as $app => $file) {
$this->useCollection($app);
require_once $file;
$collection = $this->getCollection($app);
$collection->addPrefix('/apps/' . $app);
$this->root->addCollection($collection);
}
- $this->useCollection('root');
- require_once 'settings/routes.php';
- require_once 'core/routes.php';
-
- // include ocs routes
- require_once 'ocs/routes.php';
- $collection = $this->getCollection('ocs');
- $collection->addPrefix('/ocs');
- $this->root->addCollection($collection);
+ if (!isset($this->loadedApps['core'])) {
+ $this->loadedApps['core'] = true;
+ $this->useCollection('root');
+ require_once 'settings/routes.php';
+ require_once 'core/routes.php';
+
+ // include ocs routes
+ require_once 'ocs/routes.php';
+ $collection = $this->getCollection('ocs');
+ $collection->addPrefix('/ocs');
+ $this->root->addCollection($collection);
+ }
}
/**
@@ -158,7 +177,12 @@ class Router implements IRouter {
* @throws \Exception
*/
public function match($url) {
- $this->loadRoutes();
+ if (substr($url, 0, 6) === '/apps/') {
+ list(, , $app,) = explode('/', $url, 4);
+ $this->loadRoutes($app);
+ } else {
+ $this->loadRoutes();
+ }
$matcher = new UrlMatcher($this->root, $this->context);
$parameters = $matcher->match($url);
if (isset($parameters['action'])) {