[Pkg-owncloud-commits] [owncloud] 22/107: Dont die when we're missing a route

David Prévot taffit at moszumanska.debian.org
Thu Dec 17 19:40:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit c9ac47a593cc2a32d5a2cbaa1527d5af1b3cd1a5
Author: Robin Appelman <icewind at owncloud.com>
Date:   Fri Nov 27 13:51:20 2015 +0100

    Dont die when we're missing a route
---
 lib/private/route/cachingrouter.php            |  7 +++++--
 lib/private/route/router.php                   | 21 +++++++++++++++++++--
 lib/private/server.php                         |  5 +++--
 tests/lib/appframework/routing/RoutingTest.php |  6 +++---
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/lib/private/route/cachingrouter.php b/lib/private/route/cachingrouter.php
index 734aa5a..2d10b8a 100644
--- a/lib/private/route/cachingrouter.php
+++ b/lib/private/route/cachingrouter.php
@@ -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);
 	}
 
 	/**
diff --git a/lib/private/route/router.php b/lib/private/route/router.php
index f4abfae..6d3b7c7 100644
--- a/lib/private/route/router.php
+++ b/lib/private/route/router.php
@@ -30,8 +30,10 @@
 
 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.
 	 */
diff --git a/lib/private/server.php b/lib/private/server.php
index 15ee345..dd7d0af 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -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;
 		});
diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php
index 51c191f..b063ef3 100644
--- a/tests/lib/appframework/routing/RoutingTest.php
+++ b/tests/lib/appframework/routing/RoutingTest.php
@@ -74,7 +74,7 @@ class RoutingTest extends \Test\TestCase
 		));
 
 		// router mock
-		$router = $this->getMock("\OC\Route\Router", array('create'));
+		$router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
 
 		// load route configuration
 		$container = new DIContainer('app1');
@@ -124,7 +124,7 @@ class RoutingTest extends \Test\TestCase
 		$route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
 
 		// router mock
-		$router = $this->getMock("\OC\Route\Router", array('create'));
+		$router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
 
 		// we expect create to be called once:
 		$router
@@ -148,7 +148,7 @@ class RoutingTest extends \Test\TestCase
 	private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName)
 	{
 		// router mock
-		$router = $this->getMock("\OC\Route\Router", array('create'));
+		$router = $this->getMock("\OC\Route\Router", array('create'), [\OC::$server->getLogger()]);
 
 		// route mocks
 		$container = new DIContainer('app1');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list