From 49eb0b8b28e05f708c4877e816fb70f9d135edd1 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Thu, 27 Feb 2020 11:03:15 -0500 Subject: [PATCH] [Router] Remove unused routing logic from ModuleRouter (#6023) The module path and routes calculated by the ModuleRouter are unused. In fact, the path passed to them is sometimes wrong. The CSS, JS, and Static routes are handled by the \Module class (where the path comes from the \Module::factory, not the ModuleRouter). This removes the confusing dead code. --- src/Router/BaseRouter.php | 6 +++--- src/Router/ModuleRouter.php | 27 +++------------------------ 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/Router/BaseRouter.php b/src/Router/BaseRouter.php index dae271f7141..1faf8e007e1 100644 --- a/src/Router/BaseRouter.php +++ b/src/Router/BaseRouter.php @@ -100,7 +100,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $factory->setBaseURL($baseurl); $module = \Module::factory($modulename); - $mr = new ModuleRouter($module, $this->moduledir); + $mr = new ModuleRouter($module); $request = $request->withURI($suburi); return $mr->handle($request); } @@ -120,7 +120,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface ->withAttribute("baseurl", rtrim($baseurl->__toString(), '/')) ->withAttribute("CandID", $components[0]); $module = \Module::factory("timepoint_list"); - $mr = new ModuleRouter($module, $this->moduledir); + $mr = new ModuleRouter($module); return $mr->handle($request); case 2: // CandID/SessionID, inherited from htaccess @@ -134,7 +134,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface \TimePoint::singleton($components[1]) ); $module = \Module::factory("instrument_list"); - $mr = new ModuleRouter($module, $this->moduledir); + $mr = new ModuleRouter($module); return $mr->handle($request); default: // Fall through to 404. We don't have any routes that go farther diff --git a/src/Router/ModuleRouter.php b/src/Router/ModuleRouter.php index 5c632403d8b..ec2c38cf74f 100644 --- a/src/Router/ModuleRouter.php +++ b/src/Router/ModuleRouter.php @@ -16,6 +16,7 @@ use \Psr\Http\Message\ServerRequestInterface; use \Psr\Http\Message\ResponseInterface; +use \Psr\Http\Server\RequestHandlerInterface; /** * Handles the base of a module's routing, adding authentication middleware @@ -27,7 +28,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 * @link https://www.github.com/aces/Loris/ */ -class ModuleRouter extends PrefixRouter +class ModuleRouter implements RequestHandlerInterface { /** * The module being accessed. @@ -42,31 +43,9 @@ class ModuleRouter extends PrefixRouter * @param \Module $module The module being accessed * @param string $moduledir The base directory of $module. */ - public function __construct(\Module $module, string $moduledir) + public function __construct(\Module $module) { $this->module = $module; - - $arr = [ - "/css/" => new ModuleFileRouter( - $module, - $moduledir, - "css", - "text/css" - ), - "/js/" => new ModuleFileRouter( - $module, - $moduledir, - "js", - "application/javascript" - ), - "/static/" => new ModuleFileRouter( - $module, - $moduledir, - "static", - "" - ), - ]; - parent::__construct(new \ArrayIterator($arr)); } /**