Pass the parameters from the router to the modules

This commit is contained in:
Michael 2019-11-05 05:03:05 +00:00
parent 4daa3d37c1
commit 8720094b52
2 changed files with 32 additions and 7 deletions

View file

@ -39,6 +39,11 @@ class Router
*/
private $httpMethod;
/**
* @var array Module parameters
*/
private $parameters = [];
/**
* @param array $server The $_SERVER variable
* @param RouteCollector|null $routeCollector Optional the loaded Route collector
@ -172,10 +177,12 @@ class Router
$dispatcher = new \FastRoute\Dispatcher\GroupCountBased($this->routeCollector->getData());
$moduleClass = null;
$this->parameters = [];
$routeInfo = $dispatcher->dispatch($this->httpMethod, $cmd);
if ($routeInfo[0] === Dispatcher::FOUND) {
$moduleClass = $routeInfo[1];
$this->parameters = $routeInfo[2];
} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
throw new HTTPException\MethodNotAllowedException(L10n::t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
} else {
@ -184,4 +191,14 @@ class Router
return $moduleClass;
}
/**
* Returns the module parameters.
*
* @return array parameters
*/
public function getModuleParameters()
{
return $this->parameters;
}
}