]> source.dussan.org Git - nextcloud-server.git/commitdiff
Dont die when we're missing a route
authorRobin Appelman <icewind@owncloud.com>
Fri, 27 Nov 2015 12:51:20 +0000 (13:51 +0100)
committerRobin Appelman <icewind@owncloud.com>
Fri, 27 Nov 2015 13:29:06 +0000 (14:29 +0100)
lib/private/route/cachingrouter.php
lib/private/route/router.php
lib/private/server.php

index 734aa5aea4bcf92da65f5699c3441ce0b69d8ab9..2d10b8ab691de72f235f5973d87248f8edabc41c 100644 (file)
@@ -22,6 +22,8 @@
 
 namespace OC\Route;
 
+use OCP\ILogger;
+
 class CachingRouter extends Router {
        /**
         * @var \OCP\ICache
@@ -30,10 +32,11 @@ class CachingRouter extends Router {
 
        /**
         * @param \OCP\ICache $cache
+        * @param ILogger $logger
         */
-       public function __construct($cache) {
+       public function __construct($cache, ILogger $logger) {
                $this->cache = $cache;
-               parent::__construct();
+               parent::__construct($logger);
        }
 
        /**
index f4abfae0f43f79a69d25355259cef8e07f54206b..6d3b7c742bbc471e0959ce9215c94c3fe497679b 100644 (file)
 
 namespace OC\Route;
 
+use OCP\ILogger;
 use OCP\Route\IRouter;
 use OCP\AppFramework\App;
+use Symfony\Component\Routing\Exception\RouteNotFoundException;
 use Symfony\Component\Routing\Matcher\UrlMatcher;
 use Symfony\Component\Routing\Generator\UrlGenerator;
 use Symfony\Component\Routing\RequestContext;
@@ -78,7 +80,13 @@ class Router implements IRouter {
 
        protected $loadedApps = array();
 
-       public function __construct() {
+       /**
+        * @var ILogger
+        */
+       protected $logger;
+
+       public function __construct(ILogger $logger) {
+               $this->logger = $logger;
                $baseUrl = \OC_Helper::linkTo('', 'index.php');
                if (!\OC::$CLI) {
                        $method = $_SERVER['REQUEST_METHOD'];
@@ -127,6 +135,7 @@ class Router implements IRouter {
 
        /**
         * loads the api routes
+        *
         * @return void
         */
        public function loadRoutes($app = null) {
@@ -290,6 +299,7 @@ class Router implements IRouter {
 
        /**
         * Get the url generator
+        *
         * @return \Symfony\Component\Routing\Generator\UrlGenerator
         *
         */
@@ -311,11 +321,17 @@ class Router implements IRouter {
         */
        public function generate($name, $parameters = array(), $absolute = false) {
                $this->loadRoutes();
-               return $this->getGenerator()->generate($name, $parameters, $absolute);
+               try {
+                       return $this->getGenerator()->generate($name, $parameters, $absolute);
+               } catch (RouteNotFoundException $e) {
+                       $this->logger->logException($e);
+                       return '';
+               }
        }
 
        /**
         * To isolate the variable scope used inside the $file it is required in it's own method
+        *
         * @param string $file the route file location to include
         * @param string $appName
         */
@@ -331,6 +347,7 @@ class Router implements IRouter {
         * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default
         * App will be intialized. This makes it optional to ship an
         * appinfo/application.php by using the built in query resolver
+        *
         * @param array $routes the application routes
         * @param string $appName the name of the app.
         */
index ea5937dfea44e80597c0836f7898ab8bf122edbf..7f3e3af6994527271e6a64ecf2d64718a44b568e 100644 (file)
@@ -297,10 +297,11 @@ class Server extends SimpleContainer implements IServerContainer {
                });
                $this->registerService('Router', function (Server $c) {
                        $cacheFactory = $c->getMemCacheFactory();
+                       $logger = $c->getLogger();
                        if ($cacheFactory->isAvailable()) {
-                               $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
+                               $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
                        } else {
-                               $router = new \OC\Route\Router();
+                               $router = new \OC\Route\Router($logger);
                        }
                        return $router;
                });