From 72a9c35be3dd7a1e54a1ef6a4ed29448a08c1a86 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Mon, 6 Jul 2020 16:00:58 +0200
Subject: [PATCH] Remove some IRouter methods
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is not the end. IRouter needs to burn.
But it is a start.

🎵 we didn't start the fire 🎵

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 lib/base.php                                  |  2 +-
 .../AppFramework/Routing/RouteConfig.php      |  8 +-
 lib/private/Route/Router.php                  |  8 --
 lib/private/URLGenerator.php                  |  6 +-
 lib/public/AppFramework/App.php               |  5 ++
 lib/public/Route/IRouter.php                  | 75 -------------------
 ocs/v1.php                                    |  2 +-
 tests/lib/UrlGeneratorTest.php                |  6 +-
 8 files changed, 17 insertions(+), 95 deletions(-)

diff --git a/lib/base.php b/lib/base.php
index 5b211a2d180..7f666daceb2 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -1005,7 +1005,7 @@ class OC {
 					OC_App::loadApps(['filesystem', 'logging']);
 					OC_App::loadApps();
 				}
-				OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
+				OC::$server->get(\OC\Route\Router::class)->match(\OC::$server->getRequest()->getRawPathInfo());
 				return;
 			} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
 				//header('HTTP/1.0 404 Not Found');
diff --git a/lib/private/AppFramework/Routing/RouteConfig.php b/lib/private/AppFramework/Routing/RouteConfig.php
index 1921ce65128..b382e7eb4b0 100644
--- a/lib/private/AppFramework/Routing/RouteConfig.php
+++ b/lib/private/AppFramework/Routing/RouteConfig.php
@@ -32,7 +32,7 @@ declare(strict_types=1);
 namespace OC\AppFramework\Routing;
 
 use OC\AppFramework\DependencyInjection\DIContainer;
-use OCP\Route\IRouter;
+use OC\Route\Router;
 
 /**
  * Class RouteConfig
@@ -42,7 +42,7 @@ class RouteConfig {
 	/** @var DIContainer */
 	private $container;
 
-	/** @var IRouter */
+	/** @var Router */
 	private $router;
 
 	/** @var array */
@@ -65,11 +65,11 @@ class RouteConfig {
 
 	/**
 	 * @param \OC\AppFramework\DependencyInjection\DIContainer $container
-	 * @param \OCP\Route\IRouter $router
+	 * @param \OC\Route\Router $router
 	 * @param array $routes
 	 * @internal param $appName
 	 */
-	public function __construct(DIContainer $container, IRouter $router, $routes) {
+	public function __construct(DIContainer $container, Router $router, $routes) {
 		$this->routes = $routes;
 		$this->container = $container;
 		$this->router = $router;
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index 4e1264666e4..134e2cdadf0 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -177,14 +177,6 @@ class Router implements IRouter {
 		\OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
 	}
 
-	/**
-	 * @return string
-	 * @deprecated
-	 */
-	public function getCacheKey() {
-		return '';
-	}
-
 	/**
 	 * @param string $name
 	 * @return \Symfony\Component\Routing\RouteCollection
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index d7de6cf92a2..f0de31568f4 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -39,12 +39,12 @@ declare(strict_types=1);
 
 namespace OC;
 
+use OC\Route\Router;
 use OCA\Theming\ThemingDefaults;
 use OCP\ICacheFactory;
 use OCP\IConfig;
 use OCP\IRequest;
 use OCP\IURLGenerator;
-use OCP\Route\IRouter;
 use RuntimeException;
 
 /**
@@ -57,13 +57,13 @@ class URLGenerator implements IURLGenerator {
 	private $cacheFactory;
 	/** @var IRequest */
 	private $request;
-	/** @var IRouter*/
+	/** @var Router */
 	private $router;
 
 	public function __construct(IConfig $config,
 								ICacheFactory $cacheFactory,
 								IRequest $request,
-								IRouter $router) {
+								Router $router) {
 		$this->config = $config;
 		$this->cacheFactory = $cacheFactory;
 		$this->request = $request;
diff --git a/lib/public/AppFramework/App.php b/lib/public/AppFramework/App.php
index 06d4b36384f..4cbd1f8d32c 100644
--- a/lib/public/AppFramework/App.php
+++ b/lib/public/AppFramework/App.php
@@ -41,6 +41,7 @@ declare(strict_types=1);
 namespace OCP\AppFramework;
 
 use OC\AppFramework\Routing\RouteConfig;
+use OC\Route\Router;
 use OC\ServerContainer;
 use OCP\Route\IRouter;
 
@@ -146,6 +147,10 @@ class App {
 	 * @deprecated 20.0.0 Just return an array from your routes.php
 	 */
 	public function registerRoutes(IRouter $router, array $routes) {
+		if (!($router instanceof Router)) {
+			throw new \RuntimeException('Can only setup routes with real router');
+		}
+
 		$routeConfig = new RouteConfig($this->container, $router, $routes);
 		$routeConfig->register();
 	}
diff --git a/lib/public/Route/IRouter.php b/lib/public/Route/IRouter.php
index d837265ac71..cb51cc0b640 100644
--- a/lib/public/Route/IRouter.php
+++ b/lib/public/Route/IRouter.php
@@ -36,50 +36,6 @@ namespace OCP\Route;
  */
 interface IRouter {
 
-	/**
-	 * Get the files to load the routes from
-	 *
-	 * @return string[]
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function getRoutingFiles();
-
-	/**
-	 * @return string
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function getCacheKey();
-
-	/**
-	 * Loads the routes
-	 *
-	 * @param null|string $app
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function loadRoutes($app = null);
-
-	/**
-	 * Sets the collection to use for adding routes
-	 *
-	 * @param string $name Name of the collection to use.
-	 * @return void
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function useCollection($name);
-
-	/**
-	 * returns the current collection name in use for adding routes
-	 *
-	 * @return string the collection name
-	 * @since 8.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function getCurrentCollection();
-
 	/**
 	 * Create a \OCP\Route\IRoute.
 	 *
@@ -92,35 +48,4 @@ interface IRouter {
 	 * @deprecated 9.0.0
 	 */
 	public function create($name, $pattern, array $defaults = [], array $requirements = []);
-
-	/**
-	 * Find the route matching $url.
-	 *
-	 * @param string $url The url to find
-	 * @throws \Exception
-	 * @return void
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function match($url);
-
-	/**
-	 * Get the url generator
-	 *
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function getGenerator();
-
-	/**
-	 * Generate url based on $name and $parameters
-	 *
-	 * @param string $name Name of the route to use.
-	 * @param array $parameters Parameters for the route
-	 * @param bool $absolute
-	 * @return string
-	 * @since 7.0.0
-	 * @deprecated 9.0.0
-	 */
-	public function generate($name, $parameters = [], $absolute = false);
 }
diff --git a/ocs/v1.php b/ocs/v1.php
index f4ddc80804a..e5138576584 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -58,7 +58,7 @@ try {
 	// load all apps to get all api routes properly setup
 	OC_App::loadApps();
 
-	OC::$server->getRouter()->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
+	OC::$server->get(\OC\Route\Router::class)->match('/ocsapp'.\OC::$server->getRequest()->getRawPathInfo());
 } catch (ResourceNotFoundException $e) {
 	OC_API::setContentType();
 
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index b5db39dbf39..dd2eb2ddc63 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -8,11 +8,11 @@
 
 namespace Test;
 
+use OC\Route\Router;
 use OCP\ICacheFactory;
 use OCP\IConfig;
 use OCP\IRequest;
 use OCP\IURLGenerator;
-use OCP\Route\IRouter;
 
 /**
  * Class UrlGeneratorTest
@@ -27,7 +27,7 @@ class UrlGeneratorTest extends \Test\TestCase {
 	private $cacheFactory;
 	/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
 	private $request;
-	/** @var \PHPUnit\Framework\MockObject\MockObject|IRouter */
+	/** @var \PHPUnit\Framework\MockObject\MockObject|Router */
 	private $router;
 	/** @var IURLGenerator */
 	private $urlGenerator;
@@ -39,7 +39,7 @@ class UrlGeneratorTest extends \Test\TestCase {
 		$this->config = $this->createMock(IConfig::class);
 		$this->cacheFactory = $this->createMock(ICacheFactory::class);
 		$this->request = $this->createMock(IRequest::class);
-		$this->router = $this->createMock(IRouter::class);
+		$this->router = $this->createMock(Router::class);
 		$this->urlGenerator = new \OC\URLGenerator(
 			$this->config,
 			$this->cacheFactory,
-- 
GitLab