aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Route
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2023-02-13 14:47:50 +0100
committerRobin Appelman <robin@icewind.nl>2023-02-13 22:51:14 +0100
commitb911da3e1eedff9f7df683889f0d425d47a6fd1c (patch)
tree98f290ad2f92c5aed25717f9f973ee112ba8b05e /lib/private/Route
parentb68be794644ad1e125257ab4b05e80356655537a (diff)
downloadnextcloud-server-b911da3e1eedff9f7df683889f0d425d47a6fd1c.tar.gz
nextcloud-server-b911da3e1eedff9f7df683889f0d425d47a6fd1c.zip
DI for Router
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Route')
-rw-r--r--lib/private/Route/CachingRouter.php27
-rw-r--r--lib/private/Route/Router.php26
2 files changed, 36 insertions, 17 deletions
diff --git a/lib/private/Route/CachingRouter.php b/lib/private/Route/CachingRouter.php
index f65060e710b..69fb3c986c9 100644
--- a/lib/private/Route/CachingRouter.php
+++ b/lib/private/Route/CachingRouter.php
@@ -24,20 +24,27 @@
*/
namespace OC\Route;
+use OCP\Diagnostics\IEventLogger;
+use OCP\ICache;
+use OCP\ICacheFactory;
+use OCP\IConfig;
+use OCP\IRequest;
+use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class CachingRouter extends Router {
- /**
- * @var \OCP\ICache
- */
- protected $cache;
+ protected ICache $cache;
- /**
- * @param \OCP\ICache $cache
- */
- public function __construct($cache, LoggerInterface $logger) {
- $this->cache = $cache;
- parent::__construct($logger);
+ public function __construct(
+ ICacheFactory $cacheFactory,
+ LoggerInterface $logger,
+ IRequest $request,
+ IConfig $config,
+ IEventLogger $eventLogger,
+ ContainerInterface $container
+ ) {
+ $this->cache = $cacheFactory->createLocal('route');
+ parent::__construct($logger, $request, $config, $eventLogger, $container);
}
/**
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index bdd14678fad..e2a092d861e 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -35,8 +35,11 @@ namespace OC\Route;
use OC\AppFramework\Routing\RouteParser;
use OCP\AppFramework\App;
use OCP\Diagnostics\IEventLogger;
+use OCP\IConfig;
+use OCP\IRequest;
use OCP\Route\IRouter;
use OCP\Util;
+use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@@ -66,11 +69,20 @@ class Router implements IRouter {
/** @var RequestContext */
protected $context;
private IEventLogger $eventLogger;
-
- public function __construct(LoggerInterface $logger) {
+ private IConfig $config;
+ private ContainerInterface $container;
+
+ public function __construct(
+ LoggerInterface $logger,
+ IRequest $request,
+ IConfig $config,
+ IEventLogger $eventLogger,
+ ContainerInterface $container
+ ) {
$this->logger = $logger;
+ $this->config = $config;
$baseUrl = \OC::$WEBROOT;
- if (!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
+ if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
$baseUrl .= '/index.php';
}
if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) {
@@ -78,13 +90,13 @@ class Router implements IRouter {
} else {
$method = 'GET';
}
- $request = \OC::$server->getRequest();
$host = $request->getServerHost();
$schema = $request->getServerProtocol();
$this->context = new RequestContext($baseUrl, $method, $host, $schema);
// TODO cache
$this->root = $this->getCollection('root');
- $this->eventLogger = \OC::$server->get(IEventLogger::class);
+ $this->eventLogger = $eventLogger;
+ $this->container = $container;
}
/**
@@ -253,7 +265,7 @@ class Router implements IRouter {
$this->loadRoutes('settings');
} elseif (substr($url, 0, 6) === '/core/') {
\OC::$REQUESTEDAPP = $url;
- if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
+ if (!$this->config->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
@@ -441,7 +453,7 @@ class Router implements IRouter {
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
if (class_exists($applicationClassName)) {
- $application = \OC::$server->query($applicationClassName);
+ $application = $this->container->get($applicationClassName);
} else {
$application = new App($appName);
}