Move getModule() code into App class

This commit is contained in:
Art4 2024-12-28 16:36:07 +00:00
parent 4d0a695588
commit dde8291597
2 changed files with 20 additions and 19 deletions

View file

@ -715,7 +715,24 @@ class App
/** @var Router $router */
$router = $this->container->create(Router::class);
return $router->getModule($this->container, $moduleClass);
$moduleClass = $moduleClass ?? $router->getModuleClass();
$parameters = $router->getParameters();
$dice_profiler_threshold = $this->config->get('system', 'dice_profiler_threshold', 0);
$stamp = microtime(true);
/** @var ICanHandleRequests $module */
$module = $this->container->create($moduleClass, $parameters);
if ($dice_profiler_threshold > 0) {
$dur = floatval(microtime(true) - $stamp);
if ($dur >= $dice_profiler_threshold) {
$this->logger->notice('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $moduleClass, 'parameters' => $parameters]);
}
}
return $module;
}
/**

View file

@ -319,25 +319,9 @@ class Router
}
}
public function getModule(Dice $dice, ?string $module_class = null): ICanHandleRequests
public function getParameters(): array
{
$moduleClass = $module_class ?? $this->getModuleClass();
$dice_profiler_threshold = $this->config->get('system', 'dice_profiler_threshold', 0);
$stamp = microtime(true);
/** @var ICanHandleRequests $module */
$module = $dice->create($moduleClass, $this->parameters);
if ($dice_profiler_threshold > 0) {
$dur = floatval(microtime(true) - $stamp);
if ($dur >= $dice_profiler_threshold) {
$this->logger->notice('Dice module creation lasts too long.', ['duration' => round($dur, 3), 'module' => $moduleClass, 'parameters' => $this->parameters]);
}
}
return $module;
return $this->parameters;
}
/**