mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 04:15:15 +02:00
Pass Router parameter to module content method
This commit is contained in:
parent
f21edefe15
commit
134d6d18f9
6 changed files with 25 additions and 20 deletions
|
@ -94,6 +94,14 @@ class Module
|
|||
return $this->module_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array The module parameters extracted from the route
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->module_parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True, if the current module is a backend module
|
||||
* @see Module::BACKEND_MODULES for a list
|
||||
|
|
|
@ -308,7 +308,7 @@ class Page implements ArrayAccess
|
|||
$arr = ['content' => $content];
|
||||
Hook::callAll($moduleClass . '_mod_content', $arr);
|
||||
$content = $arr['content'];
|
||||
$arr = ['content' => call_user_func([$moduleClass, 'content'], [])];
|
||||
$arr = ['content' => call_user_func([$moduleClass, 'content'], $module->getParameters())];
|
||||
Hook::callAll($moduleClass . '_mod_aftercontent', $arr);
|
||||
$content .= $arr['content'];
|
||||
} catch (HTTPException $e) {
|
||||
|
|
|
@ -65,12 +65,21 @@ class Router
|
|||
*
|
||||
* @throws HTTPException\InternalServerErrorException In case of invalid configs
|
||||
*/
|
||||
public function addRoutes(array $routes)
|
||||
public function loadRoutes(array $routes)
|
||||
{
|
||||
$routeCollector = (isset($this->routeCollector) ?
|
||||
$this->routeCollector :
|
||||
new RouteCollector(new Std(), new GroupCountBased()));
|
||||
|
||||
$this->addRoutes($routeCollector, $routes);
|
||||
|
||||
$this->routeCollector = $routeCollector;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function addRoutes(RouteCollector $routeCollector, array $routes)
|
||||
{
|
||||
foreach ($routes as $route => $config) {
|
||||
if ($this->isGroup($config)) {
|
||||
$this->addGroup($route, $config, $routeCollector);
|
||||
|
@ -80,10 +89,6 @@ class Router
|
|||
throw new HTTPException\InternalServerErrorException("Wrong route config for route '" . print_r($route, true) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->routeCollector = $routeCollector;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,15 +101,7 @@ class Router
|
|||
private function addGroup(string $groupRoute, array $routes, RouteCollector $routeCollector)
|
||||
{
|
||||
$routeCollector->addGroup($groupRoute, function (RouteCollector $routeCollector) use ($routes) {
|
||||
foreach ($routes as $route => $config) {
|
||||
if ($this->isGroup($config)) {
|
||||
$this->addGroup($route, $config, $routeCollector);
|
||||
} elseif ($this->isRoute($config)) {
|
||||
$routeCollector->addRoute($config[1], $route, $config[0]);
|
||||
}else {
|
||||
throw new HTTPException\InternalServerErrorException("Wrong route config for route '" . print_r($route, true) . "'");
|
||||
}
|
||||
}
|
||||
$this->addRoutes($routeCollector, $routes);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -174,7 +171,7 @@ class Router
|
|||
|
||||
$cmd = '/' . ltrim($cmd, '/');
|
||||
|
||||
$dispatcher = new \FastRoute\Dispatcher\GroupCountBased($this->routeCollector->getData());
|
||||
$dispatcher = new Dispatcher\GroupCountBased($this->routeCollector->getData());
|
||||
|
||||
$moduleClass = null;
|
||||
$this->parameters = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue