diff --git a/src/App.php b/src/App.php index 0345eb3adf..e0f1a0e2da 100644 --- a/src/App.php +++ b/src/App.php @@ -15,6 +15,7 @@ use Friendica\App\Page; use Friendica\App\Request; use Friendica\App\Router; use Friendica\Capabilities\ICanCreateResponses; +use Friendica\Capabilities\ICanHandleRequests; use Friendica\Content\Nav; use Friendica\Core\Config\Factory\Config; use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs; @@ -170,7 +171,6 @@ class App $this->mode->setExecutor(Mode::INDEX); $this->runFrontend( - $this->container->create(Router::class), $this->container->create(IManagePersonalConfigValues::class), $this->container->create(Page::class), $this->container->create(Nav::class), @@ -529,7 +529,6 @@ class App * * This probably should change to limit the size of this monster method. * - * @param Router $router * @param IManagePersonalConfigValues $pconfig * @param Page $page The Friendica page printing container * @param ModuleHTTPException $httpException The possible HTTP Exception container @@ -539,7 +538,6 @@ class App * @throws \ImagickException */ private function runFrontend( - Router $router, IManagePersonalConfigValues $pconfig, Page $page, Nav $nav, @@ -677,11 +675,11 @@ class App // The "view" module is required to show the theme CSS if (!$this->mode->isInstall() && !$this->mode->has(Mode::MAINTENANCEDISABLED) && $moduleName !== 'view') { - $module = $router->getModule(Maintenance::class); + $module = $this->createModuleInstance(Maintenance::class); } else { // determine the module class and save it to the module instance // @todo there's an implicit dependency due SESSION::start(), so it has to be called here (yet) - $module = $router->getModule(); + $module = $this->createModuleInstance(null); } // Display can change depending on the requested language, so it shouldn't be cached whole @@ -712,6 +710,31 @@ class App $page->logRuntime($this->config, 'runFrontend'); } + private function createModuleInstance(?string $moduleClass = null): ICanHandleRequests + { + /** @var Router $router */ + $router = $this->container->create(Router::class); + + $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; + } + /** * Log slow page executions * diff --git a/src/App/Router.php b/src/App/Router.php index 31162ec1b6..deb0155cf0 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -89,12 +89,6 @@ class Router /** @var bool */ private $isLocalUser; - /** @var float */ - private $dice_profiler_threshold; - - /** @var Dice */ - private $dice; - /** @var string */ private $baseRoutesFilepath; @@ -113,11 +107,10 @@ class Router * @param IManageConfigValues $config * @param Arguments $args * @param LoggerInterface $logger - * @param Dice $dice * @param IHandleUserSessions $userSession * @param RouteCollector|null $routeCollector */ - public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, Dice $dice, IHandleUserSessions $userSession, RouteCollector $routeCollector = null) + public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, IHandleUserSessions $userSession, RouteCollector $routeCollector = null) { $this->baseRoutesFilepath = $baseRoutesFilepath; $this->l10n = $l10n; @@ -125,11 +118,9 @@ class Router $this->lock = $lock; $this->args = $args; $this->config = $config; - $this->dice = $dice; $this->server = $server; $this->logger = $logger; $this->isLocalUser = !empty($userSession->getLocalUserId()); - $this->dice_profiler_threshold = $config->get('system', 'dice_profiler_threshold', 0); $this->routeCollector = $routeCollector ?? new RouteCollector(new Std(), new GroupCountBased()); @@ -328,23 +319,9 @@ class Router } } - public function getModule(?string $module_class = null): ICanHandleRequests + public function getParameters(): array { - $moduleClass = $module_class ?? $this->getModuleClass(); - - $stamp = microtime(true); - - /** @var ICanHandleRequests $module */ - $module = $this->dice->create($moduleClass, $this->parameters); - - if ($this->dice_profiler_threshold > 0) { - $dur = floatval(microtime(true) - $stamp); - if ($dur >= $this->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; } /** diff --git a/static/dependencies.config.php b/static/dependencies.config.php index 93d9de81ac..28ae277c21 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -219,7 +219,6 @@ return (function(string $basepath, array $getVars, array $serverVars, array $coo 'constructParams' => [ $serverVars, __DIR__ . '/routes.config.php', - [Dice::INSTANCE => Dice::SELF], null ], ],