Merge pull request #21032 from owncloud/router-error-handling
Router error handling + Base.php
This commit is contained in:
commit
a0345b9465
|
@ -469,7 +469,12 @@ class OC {
|
||||||
|
|
||||||
public static function loadAppClassPaths() {
|
public static function loadAppClassPaths() {
|
||||||
foreach (OC_APP::getEnabledApps() as $app) {
|
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)) {
|
if (file_exists($file)) {
|
||||||
require_once $file;
|
require_once $file;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace OC\Route;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\Route\IRouter;
|
use OCP\Route\IRouter;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
use OCP\Util;
|
||||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||||
use Symfony\Component\Routing\Generator\UrlGenerator;
|
use Symfony\Component\Routing\Generator\UrlGenerator;
|
||||||
|
@ -41,49 +42,26 @@ use Symfony\Component\Routing\RouteCollection;
|
||||||
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
|
||||||
class Router implements IRouter {
|
class Router implements IRouter {
|
||||||
/**
|
/** @var RouteCollection[] */
|
||||||
* @var \Symfony\Component\Routing\RouteCollection[]
|
protected $collections = [];
|
||||||
*/
|
/** @var null|RouteCollection */
|
||||||
protected $collections = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Symfony\Component\Routing\RouteCollection
|
|
||||||
*/
|
|
||||||
protected $collection = null;
|
protected $collection = null;
|
||||||
|
/** @var null|string */
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $collectionName = null;
|
protected $collectionName = null;
|
||||||
|
/** @var null|RouteCollection */
|
||||||
/**
|
|
||||||
* @var \Symfony\Component\Routing\RouteCollection
|
|
||||||
*/
|
|
||||||
protected $root = null;
|
protected $root = null;
|
||||||
|
/** @var null|UrlGenerator */
|
||||||
/**
|
|
||||||
* @var \Symfony\Component\Routing\Generator\UrlGenerator
|
|
||||||
*/
|
|
||||||
protected $generator = null;
|
protected $generator = null;
|
||||||
|
/** @var string[] */
|
||||||
/**
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $routingFiles;
|
protected $routingFiles;
|
||||||
|
/** @var bool */
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $cacheKey;
|
|
||||||
|
|
||||||
protected $loaded = false;
|
protected $loaded = false;
|
||||||
|
/** @var array */
|
||||||
protected $loadedApps = array();
|
protected $loadedApps = [];
|
||||||
|
/** @var ILogger */
|
||||||
/**
|
|
||||||
* @var ILogger
|
|
||||||
*/
|
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
/** @var RequestContext */
|
||||||
|
protected $context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
|
@ -114,7 +92,7 @@ class Router implements IRouter {
|
||||||
*/
|
*/
|
||||||
public function getRoutingFiles() {
|
public function getRoutingFiles() {
|
||||||
if (!isset($this->routingFiles)) {
|
if (!isset($this->routingFiles)) {
|
||||||
$this->routingFiles = array();
|
$this->routingFiles = [];
|
||||||
foreach (\OC_APP::getEnabledApps() as $app) {
|
foreach (\OC_APP::getEnabledApps() as $app) {
|
||||||
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
|
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
|
@ -126,23 +104,9 @@ class Router implements IRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Loads the routes
|
||||||
*/
|
|
||||||
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
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @param null|string $app
|
||||||
*/
|
*/
|
||||||
public function loadRoutes($app = null) {
|
public function loadRoutes($app = null) {
|
||||||
$requestedApp = $app;
|
$requestedApp = $app;
|
||||||
|
@ -157,10 +121,10 @@ class Router implements IRouter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
|
$file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
|
||||||
if (file_exists($file)) {
|
if ($file !== false && file_exists($file)) {
|
||||||
$routingFiles = array($app => $file);
|
$routingFiles = [$app => $file];
|
||||||
} else {
|
} else {
|
||||||
$routingFiles = array();
|
$routingFiles = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
|
\OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
|
||||||
|
@ -183,12 +147,12 @@ class Router implements IRouter {
|
||||||
if (!isset($this->loadedApps['core'])) {
|
if (!isset($this->loadedApps['core'])) {
|
||||||
$this->loadedApps['core'] = true;
|
$this->loadedApps['core'] = true;
|
||||||
$this->useCollection('root');
|
$this->useCollection('root');
|
||||||
require_once 'settings/routes.php';
|
require_once __DIR__ . '/../../../settings/routes.php';
|
||||||
require_once 'core/routes.php';
|
require_once __DIR__ . '/../../../core/routes.php';
|
||||||
}
|
}
|
||||||
if ($this->loaded) {
|
if ($this->loaded) {
|
||||||
// include ocs routes, must be loaded last for /ocs prefix
|
// 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 = $this->getCollection('ocs');
|
||||||
$collection->addPrefix('/ocs');
|
$collection->addPrefix('/ocs');
|
||||||
$this->root->addCollection($collection);
|
$this->root->addCollection($collection);
|
||||||
|
@ -196,6 +160,14 @@ class Router implements IRouter {
|
||||||
\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
|
\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function getCacheKey() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \Symfony\Component\Routing\RouteCollection
|
* @return \Symfony\Component\Routing\RouteCollection
|
||||||
|
@ -237,7 +209,10 @@ class Router implements IRouter {
|
||||||
* @param array $requirements An array of requirements for parameters (regexes)
|
* @param array $requirements An array of requirements for parameters (regexes)
|
||||||
* @return \OC\Route\Route
|
* @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);
|
$route = new Route($pattern, $defaults, $requirements);
|
||||||
$this->collection->add($name, $route);
|
$this->collection->add($name, $route);
|
||||||
return $route;
|
return $route;
|
||||||
|
@ -260,7 +235,7 @@ class Router implements IRouter {
|
||||||
$this->loadRoutes($app);
|
$this->loadRoutes($app);
|
||||||
} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
|
} else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
|
||||||
\OC::$REQUESTEDAPP = $url;
|
\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();
|
\OC_App::loadApps();
|
||||||
}
|
}
|
||||||
$this->loadRoutes('core');
|
$this->loadRoutes('core');
|
||||||
|
@ -325,7 +300,9 @@ class Router implements IRouter {
|
||||||
* @param bool $absolute
|
* @param bool $absolute
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = array(), $absolute = false) {
|
public function generate($name,
|
||||||
|
$parameters = [],
|
||||||
|
$absolute = false) {
|
||||||
$this->loadRoutes();
|
$this->loadRoutes();
|
||||||
try {
|
try {
|
||||||
$referenceType = UrlGenerator::ABSOLUTE_URL;
|
$referenceType = UrlGenerator::ABSOLUTE_URL;
|
||||||
|
@ -376,6 +353,4 @@ class Router implements IRouter {
|
||||||
$application->registerRoutes($this, $routes);
|
$application->registerRoutes($this, $routes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace OCP\Route;
|
||||||
*
|
*
|
||||||
* @package OCP\Route
|
* @package OCP\Route
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
interface IRouter {
|
interface IRouter {
|
||||||
|
|
||||||
|
@ -37,19 +38,23 @@ interface IRouter {
|
||||||
*
|
*
|
||||||
* @return string[]
|
* @return string[]
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getRoutingFiles();
|
public function getRoutingFiles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getCacheKey();
|
public function getCacheKey();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads the api routes
|
* Loads the routes
|
||||||
* @return void
|
*
|
||||||
|
* @param null|string $app
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function loadRoutes($app = null);
|
public function loadRoutes($app = null);
|
||||||
|
|
||||||
|
@ -59,6 +64,7 @@ interface IRouter {
|
||||||
* @param string $name Name of the collection to use.
|
* @param string $name Name of the collection to use.
|
||||||
* @return void
|
* @return void
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function useCollection($name);
|
public function useCollection($name);
|
||||||
|
|
||||||
|
@ -67,6 +73,7 @@ interface IRouter {
|
||||||
*
|
*
|
||||||
* @return string the collection name
|
* @return string the collection name
|
||||||
* @since 8.0.0
|
* @since 8.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getCurrentCollection();
|
public function getCurrentCollection();
|
||||||
|
|
||||||
|
@ -79,6 +86,7 @@ interface IRouter {
|
||||||
* @param array $requirements An array of requirements for parameters (regexes)
|
* @param array $requirements An array of requirements for parameters (regexes)
|
||||||
* @return \OCP\Route\IRoute
|
* @return \OCP\Route\IRoute
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function create($name, $pattern, array $defaults = array(), array $requirements = array());
|
public function create($name, $pattern, array $defaults = array(), array $requirements = array());
|
||||||
|
|
||||||
|
@ -89,6 +97,7 @@ interface IRouter {
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @return void
|
* @return void
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function match($url);
|
public function match($url);
|
||||||
|
|
||||||
|
@ -96,6 +105,7 @@ interface IRouter {
|
||||||
* Get the url generator
|
* Get the url generator
|
||||||
*
|
*
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getGenerator();
|
public function getGenerator();
|
||||||
|
|
||||||
|
@ -107,6 +117,7 @@ interface IRouter {
|
||||||
* @param bool $absolute
|
* @param bool $absolute
|
||||||
* @return string
|
* @return string
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
|
* @deprecated 9.0.0
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = array(), $absolute = false);
|
public function generate($name, $parameters = array(), $absolute = false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue