diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-08-11 22:28:29 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-08-19 22:00:47 +0200 |
commit | 387cac4c5fb9c797a94b8312778cd503cc951dda (patch) | |
tree | 7c391f107f498100b2fb16d182ff069dfe44f2b8 /lib/private | |
parent | 053ee7b3860c352004bede82d040b4bd34ecb072 (diff) | |
download | nextcloud-server-387cac4c5fb9c797a94b8312778cd503cc951dda.tar.gz nextcloud-server-387cac4c5fb9c797a94b8312778cd503cc951dda.zip |
Properly inject IRouter into URLGenerator to properly encapsulate tests
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Route/Router.php | 2 | ||||
-rw-r--r-- | lib/private/Server.php | 11 | ||||
-rw-r--r-- | lib/private/URLGenerator.php | 17 |
3 files changed, 10 insertions, 20 deletions
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index ec91e08472c..94c637e5e0d 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -73,7 +73,7 @@ class Router implements IRouter { $this->logger = $logger; $baseUrl = \OC::$WEBROOT; if (!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { - $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); + $baseUrl .= '/index.php'; } if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) { $method = $_SERVER['REQUEST_METHOD']; diff --git a/lib/private/Server.php b/lib/private/Server.php index a934628a047..9b452f21ce1 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -644,16 +644,7 @@ class Server extends ServerContainer implements IServerContainer { /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('L10NFactory', IFactory::class); - $this->registerService(IURLGenerator::class, function (Server $c) { - $config = $c->getConfig(); - $cacheFactory = $c->getMemCacheFactory(); - $request = $c->getRequest(); - return new \OC\URLGenerator( - $config, - $cacheFactory, - $request - ); - }); + $this->registerAlias(IURLGenerator::class, URLGenerator::class); /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index e90d8cf1d1c..4da6a91b6c9 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -44,6 +44,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\Route\IRouter; use RuntimeException; /** @@ -56,18 +57,17 @@ class URLGenerator implements IURLGenerator { private $cacheFactory; /** @var IRequest */ private $request; + /** @var IRouter*/ + private $router; - /** - * @param IConfig $config - * @param ICacheFactory $cacheFactory - * @param IRequest $request - */ public function __construct(IConfig $config, ICacheFactory $cacheFactory, - IRequest $request) { + IRequest $request, + IRouter $router) { $this->config = $config; $this->cacheFactory = $cacheFactory; $this->request = $request; + $this->router = $router; } /** @@ -80,8 +80,7 @@ class URLGenerator implements IURLGenerator { * Returns a url to the given route. */ public function linkToRoute(string $routeName, array $arguments = []): string { - // TODO: mock router - return \OC::$server->getRouter()->generate($routeName, $arguments); + return $this->router->generate($routeName, $arguments); } /** @@ -97,7 +96,7 @@ class URLGenerator implements IURLGenerator { } public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string { - $route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false); + $route = $this->router->generate('ocs.'.$routeName, $arguments, false); $indexPhpPos = strpos($route, '/index.php/'); if ($indexPhpPos !== false) { |