From 52c6f93c9adc497decc7abf75b17ecf345b279da Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 22 Jan 2025 12:11:06 +0000 Subject: [PATCH] Inject Mode into App::runFrontend() via parameter --- src/App.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/App.php b/src/App.php index c823cfd5b3..6cda9d989b 100644 --- a/src/App.php +++ b/src/App.php @@ -168,6 +168,7 @@ class App $this->registerTemplateEngine(); $this->runFrontend( + $this->mode, $this->container->create(IManagePersonalConfigValues::class), $this->container->create(Page::class), $this->container->create(Nav::class), @@ -340,6 +341,7 @@ class App * @throws \ImagickException */ private function runFrontend( + Mode $mode, IManagePersonalConfigValues $pconfig, Page $page, Nav $nav, @@ -347,7 +349,7 @@ class App float $start_time, ServerRequestInterface $request ) { - $this->mode->setExecutor(Mode::INDEX); + $mode->setExecutor(Mode::INDEX); $httpInput = new HTTPInputData($request->getServerParams()); $serverVars = $request->getServerParams(); @@ -366,11 +368,11 @@ class App try { // Missing DB connection: ERROR - if ($this->mode->has(Mode::LOCALCONFIGPRESENT) && !$this->mode->has(Mode::DBAVAILABLE)) { + if ($mode->has(Mode::LOCALCONFIGPRESENT) && !$mode->has(Mode::DBAVAILABLE)) { throw new HTTPException\InternalServerErrorException($this->l10n->t('Apologies but the website is unavailable at the moment.')); } - if (!$this->mode->isInstall()) { + if (!$mode->isInstall()) { // Force SSL redirection if ($this->config->get('system', 'force_ssl') && (empty($serverVars['HTTPS']) || $serverVars['HTTPS'] === 'off') && @@ -384,7 +386,7 @@ class App DID::routeRequest($this->args->getCommand(), $serverVars); - if ($this->mode->isNormal() && !$this->mode->isBackend()) { + if ($mode->isNormal() && !$mode->isBackend()) { $requester = HTTPSignature::getSigner('', $serverVars); if (!empty($requester)) { OpenWebAuth::addVisitorCookieForHandle($requester); @@ -392,7 +394,7 @@ class App } // ZRL - if (!empty($queryVars['zrl']) && $this->mode->isNormal() && !$this->mode->isBackend() && !$this->session->getLocalUserId()) { + if (!empty($queryVars['zrl']) && $mode->isNormal() && !$mode->isBackend() && !$this->session->getLocalUserId()) { // Only continue when the given profile link seems valid. // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($queryVars['zrl'], PHP_URL_QUERY) == '') && @@ -407,12 +409,12 @@ class App } } - if (!empty($queryVars['owt']) && $this->mode->isNormal()) { + if (!empty($queryVars['owt']) && $mode->isNormal()) { $token = $queryVars['owt']; OpenWebAuth::init($token); } - if (!$this->mode->isBackend()) { + if (!$mode->isBackend()) { $this->auth->withSession(); } @@ -428,7 +430,7 @@ class App // in install mode, any url loads install module // but we need "view" module for stylesheet - if ($this->mode->isInstall() && $moduleName !== 'install') { + if ($mode->isInstall() && $moduleName !== 'install') { $this->baseURL->redirect('install'); } else { Core\Update::check($this->appHelper->getBasePath(), false); @@ -478,7 +480,7 @@ class App $page['page_title'] = $moduleName; // The "view" module is required to show the theme CSS - if (!$this->mode->isInstall() && !$this->mode->has(Mode::MAINTENANCEDISABLED) && $moduleName !== 'view') { + if (!$mode->isInstall() && !$mode->has(Mode::MAINTENANCEDISABLED) && $moduleName !== 'view') { $module = $this->createModuleInstance(Maintenance::class); } else { // determine the module class and save it to the module instance @@ -500,7 +502,7 @@ class App // Wrapping HTML responses in the theme template if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { - $response = $page->run($this->appHelper, $this->session, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId()); + $response = $page->run($this->appHelper, $this->session, $this->baseURL, $this->args, $mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig, $nav, $this->session->getLocalUserId()); } $this->logger->debug('Request processed sucessfully', ['response' => $response->getStatusCode(), 'address' => $serverVars['REMOTE_ADDR'] ?? '', 'request' => $requeststring, 'referer' => $serverVars['HTTP_REFERER'] ?? '', 'user-agent' => $serverVars['HTTP_USER_AGENT'] ?? '', 'duration' => number_format(microtime(true) - $request_start, 3)]);