diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-11-23 07:47:47 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-02 17:57:04 +0200 |
commit | 4b1576e97807a2125ff0adde93a9be81127c9011 (patch) | |
tree | 5a7a920f4663d1fef6187a7efcf2abb86c0a2bbc /lib/private/Route | |
parent | d0cf20cc51c6f7d119d21d3ea3ed81b9b52f2c9d (diff) | |
download | nextcloud-server-4b1576e97807a2125ff0adde93a9be81127c9011.tar.gz nextcloud-server-4b1576e97807a2125ff0adde93a9be81127c9011.zip |
First attempt to check against core routes before loading all app routes
Most of the time we will find a matching route in either the loaded ones
matched on the URL or in the core ones. Therfore we can attempt to try
those first and only load all app routes if no match was found by the
Symfony URLMatcher.
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Route')
-rw-r--r-- | lib/private/Route/Router.php | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index 2ed8a1991e7..ac9508b3069 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -234,32 +234,29 @@ class Router implements IRouter { * @throws \Exception * @return array */ - public function findMatchingRoute(string $url): array { - if (substr($url, 0, 6) === '/apps/') { + public function findMatchingRoute(string $url, bool $loadAll = false): array { + if (strpos($url, '/apps/') === 0) { // empty string / 'apps' / $app / rest of the route [, , $app,] = explode('/', $url, 4); $app = \OC_App::cleanAppId($app); \OC::$REQUESTEDAPP = $app; $this->loadRoutes($app); - } elseif (substr($url, 0, 13) === '/ocsapp/apps/') { + } elseif (strpos($url, '/ocsapp/apps/') === 0) { // empty string / 'ocsapp' / 'apps' / $app / rest of the route [, , , $app,] = explode('/', $url, 5); $app = \OC_App::cleanAppId($app); \OC::$REQUESTEDAPP = $app; $this->loadRoutes($app); - } elseif (substr($url, 0, 10) === '/settings/') { + } elseif (strpos($url, '/settings/') === 0) { $this->loadRoutes('settings'); - } elseif (substr($url, 0, 6) === '/core/') { - \OC::$REQUESTEDAPP = $url; - if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) { - \OC_App::loadApps(); - } - $this->loadRoutes('core'); - } else { - $this->loadRoutes(); } + \OC::$REQUESTEDAPP = $url; + if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) { + \OC_App::loadApps(); + } + $this->loadRoutes('core'); $matcher = new UrlMatcher($this->root, $this->context); try { @@ -272,6 +269,11 @@ class Router implements IRouter { try { $parameters = $matcher->match($url . '/'); } catch (ResourceNotFoundException $newException) { + // Attempt to fallback to load all routes if none of the above route patterns matches and the route is not in core + if (!$loadAll) { + $this->loadRoutes(); + return $this->findMatchingRoute($url, true); + } // If we still didn't match a route, we throw the original exception throw $e; } |