isBackendUserCookieSet($request); $this->timeTracker->setEnabled($timeTrackingEnabled); $this->timeTracker->start(microtime(true)); $this->timeTracker->push(''); $response = $handler->handle($request); // Finish time tracking $this->timeTracker->pull(); $this->timeTracker->finish(); if ($this->isDebugModeEnabled()) { return $response->withHeader('X-TYPO3-Parsetime', $this->timeTracker->getParseTime() . 'ms'); } return $response; } /** * This middleware is run pretty early in the FE chain to initialize correctly. * It however should only add the response header if debugging is enabled in TypoScript 'config', * which is not available in the incoming Request, yet. * It thus listens on the AfterTypoScriptDeterminedEvent to set $this->isDebugEnabledInTypoScriptConfig. */ #[AsEventListener('typo3-frontend/timetracker-init-middleware')] public function typoScriptDeterminedListener(AfterTypoScriptDeterminedEvent $event): void { $typoScriptConfig = $event->getFrontendTypoScript()->getConfigArray(); if (!empty($typoScriptConfig['debug'] ?? false)) { $this->isDebugEnabledInTypoScriptConfig = true; } } private function isBackendUserCookieSet(ServerRequestInterface $request): bool { $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user'; return !empty($request->getCookieParams()[$configuredCookieName]); } private function isDebugModeEnabled(): bool { if ($this->isDebugEnabledInTypoScriptConfig) { return true; } return !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['debug']); } }