Skip to content

Commit

Permalink
[Router] Remove unused routing logic from ModuleRouter (#6023)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
driusan authored Feb 27, 2020
1 parent 91950c2 commit 49eb0b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/Router/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand All @@ -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
Expand Down
27 changes: 3 additions & 24 deletions src/Router/ModuleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit 49eb0b8

Please sign in to comment.