*/
private $module_class;
+ /**
+ * @var array The module parameters
+ */
+ private $module_parameters;
+
/**
* @var bool true, if the module is a backend module
*/
return $this->isBackend;
}
- public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, bool $isBackend = false, bool $printNotAllowedAddon = false)
+ public function __construct(string $module = self::DEFAULT, string $moduleClass = self::DEFAULT_CLASS, array $moduleParameters = [], bool $isBackend = false, bool $printNotAllowedAddon = false)
{
$this->module = $module;
$this->module_class = $moduleClass;
+ $this->module_parameters = $moduleParameters;
$this->isBackend = $isBackend;
$this->printNotAllowedAddon = $printNotAllowedAddon;
}
$isBackend = in_array($module, Module::BACKEND_MODULES);;
- return new Module($module, $this->module_class, $isBackend, $this->printNotAllowedAddon);
+ return new Module($module, $this->module_class, [], $isBackend, $this->printNotAllowedAddon);
}
/**
$printNotAllowedAddon = false;
$module_class = null;
+ $module_parameters = [];
/**
* ROUTING
*
**/
try {
$module_class = $router->getModuleClass($args->getCommand());
+ $module_parameters = $router->getModuleParameters();
} catch (MethodNotAllowedException $e) {
$module_class = MethodNotAllowed::class;
} catch (NotFoundException $e) {
$module_class = $module_class ?: PageNotFound::class;
}
- return new Module($this->module, $module_class, $this->isBackend, $printNotAllowedAddon);
+ return new Module($this->module, $module_class, $module_parameters, $this->isBackend, $printNotAllowedAddon);
}
/**
Core\Hook::callAll($this->module . '_mod_init', $placeholder);
- call_user_func([$this->module_class, 'init']);
+ call_user_func([$this->module_class, 'init'], $this->module_parameters);
// "rawContent" is especially meant for technical endpoints.
// This endpoint doesn't need any theme initialization or other comparable stuff.
- call_user_func([$this->module_class, 'rawContent']);
+ call_user_func([$this->module_class, 'rawContent'], $this->module_parameters);
if ($server['REQUEST_METHOD'] === 'POST') {
Core\Hook::callAll($this->module . '_mod_post', $post);
- call_user_func([$this->module_class, 'post']);
+ call_user_func([$this->module_class, 'post'], $this->module_parameters);
}
Core\Hook::callAll($this->module . '_mod_afterpost', $placeholder);
- call_user_func([$this->module_class, 'afterpost']);
+ call_user_func([$this->module_class, 'afterpost'], $this->module_parameters);
}
}
*/
private $httpMethod;
+ /**
+ * @var array Module parameters
+ */
+ private $parameters = [];
+
/**
* @param array $server The $_SERVER variable
* @param RouteCollector|null $routeCollector Optional the loaded Route collector
$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 {
return $moduleClass;
}
+
+ /**
+ * Returns the module parameters.
+ *
+ * @return array parameters
+ */
+ public function getModuleParameters()
+ {
+ return $this->parameters;
+ }
}