From 0e561afe79e7da44afef285e49ef6e0851db25f0 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 8 Dec 2015 10:18:34 +0100 Subject: [PATCH 1/3] Check if app does exists --- lib/base.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index 2cace2a0a0..d6ef01ccbf 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; } From 9bf01283e72716d4f94ca6893ff3d6cda6680d44 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 8 Dec 2015 10:18:59 +0100 Subject: [PATCH 2/3] Cleanup router code - Some functions are entirely broken - PHPDoc etc... --- lib/private/route/router.php | 103 +++++++++++++---------------------- lib/public/route/irouter.php | 13 ++++- 2 files changed, 50 insertions(+), 66 deletions(-) diff --git a/lib/private/route/router.php b/lib/private/route/router.php index 8d31d44885..5cfddca966 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); @@ -196,6 +160,14 @@ class Router implements IRouter { \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); } + /** + * @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 3f5b58ac41..e65dc23004 100644 --- a/lib/public/route/irouter.php +++ b/lib/public/route/irouter.php @@ -37,6 +37,7 @@ interface IRouter { * * @return string[] * @since 7.0.0 + * @deprecated 9.0.0 */ public function getRoutingFiles(); @@ -47,9 +48,11 @@ interface IRouter { 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 +62,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 +71,7 @@ interface IRouter { * * @return string the collection name * @since 8.0.0 + * @deprecated 9.0.0 */ public function getCurrentCollection(); @@ -79,6 +84,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 +95,7 @@ interface IRouter { * @throws \Exception * @return void * @since 7.0.0 + * @deprecated 9.0.0 */ public function match($url); @@ -96,6 +103,7 @@ interface IRouter { * Get the url generator * * @since 7.0.0 + * @deprecated 9.0.0 */ public function getGenerator(); @@ -107,6 +115,7 @@ interface IRouter { * @param bool $absolute * @return string * @since 7.0.0 + * @deprecated 9.0.0 */ public function generate($name, $parameters = array(), $absolute = false); From 34c8249799c2fc89af021a085f4b15c3156d1b11 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 23 Dec 2015 15:22:30 +0100 Subject: [PATCH 3/3] Deprecate remaining function and entire class --- lib/public/route/irouter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/public/route/irouter.php b/lib/public/route/irouter.php index e65dc23004..63e7b9b620 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 { @@ -44,6 +45,7 @@ interface IRouter { /** * @return string * @since 7.0.0 + * @deprecated 9.0.0 */ public function getCacheKey();