summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-08 10:06:54 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-08 10:06:54 +0100
commita0345b94650f9ded7b86d53b27624557868747e4 (patch)
treec54ff3e8387e8f394fd3b01c76f4c2a43ef11d2d /lib
parenta1a8a06042e1f420fbdc6ff8cc1abead1d60c2ad (diff)
parent34c8249799c2fc89af021a085f4b15c3156d1b11 (diff)
downloadnextcloud-server-a0345b94650f9ded7b86d53b27624557868747e4.tar.gz
nextcloud-server-a0345b94650f9ded7b86d53b27624557868747e4.zip
Merge pull request #21032 from owncloud/router-error-handling
Router error handling + Base.php
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php7
-rw-r--r--lib/private/route/router.php103
-rw-r--r--lib/public/route/irouter.php15
3 files changed, 58 insertions, 67 deletions
diff --git a/lib/base.php b/lib/base.php
index 2cace2a0a06..d6ef01ccbf7 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -469,7 +469,12 @@ class OC {
public static function loadAppClassPaths() {
foreach (OC_APP::getEnabledApps() as $app) {
- $file = OC_App::getAppPath($app) . '/appinfo/classpath.php';
+ $appPath = OC_App::getAppPath($app);
+ if ($appPath === false) {
+ continue;
+ }
+
+ $file = $appPath . '/appinfo/classpath.php';
if (file_exists($file)) {
require_once $file;
}
diff --git a/lib/private/route/router.php b/lib/private/route/router.php
index 8d31d448855..5cfddca966a 100644
--- a/lib/private/route/router.php
+++ b/lib/private/route/router.php
@@ -33,6 +33,7 @@ namespace OC\Route;
use OCP\ILogger;
use OCP\Route\IRouter;
use OCP\AppFramework\App;
+use OCP\Util;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Generator\UrlGenerator;
@@ -41,49 +42,26 @@ use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
class Router implements IRouter {
- /**
- * @var \Symfony\Component\Routing\RouteCollection[]
- */
- protected $collections = array();
-
- /**
- * @var \Symfony\Component\Routing\RouteCollection
- */
+ /** @var RouteCollection[] */
+ protected $collections = [];
+ /** @var null|RouteCollection */
protected $collection = null;
-
- /**
- * @var string
- */
+ /** @var null|string */
protected $collectionName = null;
-
- /**
- * @var \Symfony\Component\Routing\RouteCollection
- */
+ /** @var null|RouteCollection */
protected $root = null;
-
- /**
- * @var \Symfony\Component\Routing\Generator\UrlGenerator
- */
+ /** @var null|UrlGenerator */
protected $generator = null;
-
- /**
- * @var string[]
- */
+ /** @var string[] */
protected $routingFiles;
-
- /**
- * @var string
- */
- protected $cacheKey;
-
+ /** @var bool */
protected $loaded = false;
-
- protected $loadedApps = array();
-
- /**
- * @var ILogger
- */
+ /** @var array */
+ protected $loadedApps = [];
+ /** @var ILogger */
protected $logger;
+ /** @var RequestContext */
+ protected $context;
/**
* @param ILogger $logger
@@ -114,7 +92,7 @@ class Router implements IRouter {
*/
public function getRoutingFiles() {
if (!isset($this->routingFiles)) {
- $this->routingFiles = array();
+ $this->routingFiles = [];
foreach (\OC_APP::getEnabledApps() as $app) {
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
if (file_exists($file)) {
@@ -126,23 +104,9 @@ class Router implements IRouter {
}
/**
- * @return string
- */
- public function getCacheKey() {
- if (!isset($this->cacheKey)) {
- $files = $this->getRoutingFiles();
- $files[] = 'settings/routes.php';
- $files[] = 'core/routes.php';
- $files[] = 'ocs/routes.php';
- $this->cacheKey = \OC\Cache::generateCacheKeyFromFiles($files);
- }
- return $this->cacheKey;
- }
-
- /**
- * loads the api routes
+ * Loads the routes
*
- * @return void
+ * @param null|string $app
*/
public function loadRoutes($app = null) {
$requestedApp = $app;
@@ -157,10 +121,10 @@ class Router implements IRouter {
return;
}
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
- if (file_exists($file)) {
- $routingFiles = array($app => $file);
+ if ($file !== false && file_exists($file)) {
+ $routingFiles = [$app => $file];
} else {
- $routingFiles = array();
+ $routingFiles = [];
}
}
\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
@@ -183,12 +147,12 @@ class Router implements IRouter {
if (!isset($this->loadedApps['core'])) {
$this->loadedApps['core'] = true;
$this->useCollection('root');
- require_once 'settings/routes.php';
- require_once 'core/routes.php';
+ require_once __DIR__ . '/../../../settings/routes.php';
+ require_once __DIR__ . '/../../../core/routes.php';
}
if ($this->loaded) {
// include ocs routes, must be loaded last for /ocs prefix
- require_once 'ocs/routes.php';
+ require_once __DIR__ . '/../../../ocs/routes.php';
$collection = $this->getCollection('ocs');
$collection->addPrefix('/ocs');
$this->root->addCollection($collection);
@@ -197,6 +161,14 @@ class Router implements IRouter {
}
/**
+ * @return string
+ * @deprecated
+ */
+ public function getCacheKey() {
+ return '';
+ }
+
+ /**
* @param string $name
* @return \Symfony\Component\Routing\RouteCollection
*/
@@ -237,7 +209,10 @@ class Router implements IRouter {
* @param array $requirements An array of requirements for parameters (regexes)
* @return \OC\Route\Route
*/
- public function create($name, $pattern, array $defaults = array(), array $requirements = array()) {
+ public function create($name,
+ $pattern,
+ array $defaults = [],
+ array $requirements = []) {
$route = new Route($pattern, $defaults, $requirements);
$this->collection->add($name, $route);
return $route;
@@ -260,7 +235,7 @@ class Router implements IRouter {
$this->loadRoutes($app);
} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
\OC::$REQUESTEDAPP = $url;
- if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !\OCP\Util::needUpgrade()) {
+ if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
@@ -325,7 +300,9 @@ class Router implements IRouter {
* @param bool $absolute
* @return string
*/
- public function generate($name, $parameters = array(), $absolute = false) {
+ public function generate($name,
+ $parameters = [],
+ $absolute = false) {
$this->loadRoutes();
try {
$referenceType = UrlGenerator::ABSOLUTE_URL;
@@ -376,6 +353,4 @@ class Router implements IRouter {
$application->registerRoutes($this, $routes);
}
}
-
-
}
diff --git a/lib/public/route/irouter.php b/lib/public/route/irouter.php
index 3f5b58ac416..63e7b9b6202 100644
--- a/lib/public/route/irouter.php
+++ b/lib/public/route/irouter.php
@@ -29,6 +29,7 @@ namespace OCP\Route;
*
* @package OCP\Route
* @since 7.0.0
+ * @deprecated 9.0.0
*/
interface IRouter {
@@ -37,19 +38,23 @@ interface IRouter {
*
* @return string[]
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function getRoutingFiles();
/**
* @return string
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function getCacheKey();
/**
- * loads the api routes
- * @return void
+ * Loads the routes
+ *
+ * @param null|string $app
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function loadRoutes($app = null);
@@ -59,6 +64,7 @@ interface IRouter {
* @param string $name Name of the collection to use.
* @return void
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function useCollection($name);
@@ -67,6 +73,7 @@ interface IRouter {
*
* @return string the collection name
* @since 8.0.0
+ * @deprecated 9.0.0
*/
public function getCurrentCollection();
@@ -79,6 +86,7 @@ interface IRouter {
* @param array $requirements An array of requirements for parameters (regexes)
* @return \OCP\Route\IRoute
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function create($name, $pattern, array $defaults = array(), array $requirements = array());
@@ -89,6 +97,7 @@ interface IRouter {
* @throws \Exception
* @return void
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function match($url);
@@ -96,6 +105,7 @@ interface IRouter {
* Get the url generator
*
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function getGenerator();
@@ -107,6 +117,7 @@ interface IRouter {
* @param bool $absolute
* @return string
* @since 7.0.0
+ * @deprecated 9.0.0
*/
public function generate($name, $parameters = array(), $absolute = false);