namespace OC\Route;
+use OCP\ILogger;
+
class CachingRouter extends Router {
/**
* @var \OCP\ICache
/**
* @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);
}
/**
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;
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'];
/**
* loads the api routes
+ *
* @return void
*/
public function loadRoutes($app = null) {
/**
* Get the url generator
+ *
* @return \Symfony\Component\Routing\Generator\UrlGenerator
*
*/
*/
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
*/
* \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.
*/
});
$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;
});