‪TYPO3CMS  10.4
TimeTrackerInitialization.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use Psr\Http\Server\MiddlewareInterface;
23 use Psr\Http\Server\RequestHandlerInterface;
26 
32 class ‪TimeTrackerInitialization implements MiddlewareInterface
33 {
37  protected ‪$timeTracker;
38 
40  {
41  $this->timeTracker = ‪$timeTracker;
42  }
43 
51  public function ‪process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
52  {
53  $timeTrackingEnabled = $this->‪isBackendUserCookieSet($request);
54  $this->timeTracker->setEnabled($timeTrackingEnabled);
55  $this->timeTracker->start(microtime(true));
56  $this->timeTracker->push('');
57 
58  $response = $handler->handle($request);
59 
60  // Finish time tracking
61  $this->timeTracker->pull();
62  $this->timeTracker->finish();
63 
64  if ($this->‪isDebugModeEnabled()) {
65  return $response->withHeader('X-TYPO3-Parsetime', $this->timeTracker->getParseTime() . 'ms');
66  }
67  return $response;
68  }
69 
70  protected function ‪isBackendUserCookieSet(ServerRequestInterface $request): bool
71  {
72  $configuredCookieName = trim(‪$GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']) ?: 'be_typo_user';
73  return !empty($request->getCookieParams()[$configuredCookieName]);
74  }
75 
76  protected function ‪isDebugModeEnabled(): bool
77  {
78  $controller = ‪$GLOBALS['TSFE'];
79  if ($controller instanceof ‪TypoScriptFrontendController && !empty($controller->config['config']['debug'] ?? false)) {
80  return true;
81  }
82  return !empty(‪$GLOBALS['TYPO3_CONF_VARS']['FE']['debug']);
83  }
84 }
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization\isBackendUserCookieSet
‪isBackendUserCookieSet(ServerRequestInterface $request)
Definition: TimeTrackerInitialization.php:69
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization
Definition: TimeTrackerInitialization.php:33
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization\isDebugModeEnabled
‪isDebugModeEnabled()
Definition: TimeTrackerInitialization.php:75
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization\$timeTracker
‪TimeTracker $timeTracker
Definition: TimeTrackerInitialization.php:36
‪TYPO3\CMS\Frontend\Middleware
Definition: BackendUserAuthenticator.php:18
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization\process
‪ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)
Definition: TimeTrackerInitialization.php:50
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\Middleware\TimeTrackerInitialization\__construct
‪__construct(TimeTracker $timeTracker)
Definition: TimeTrackerInitialization.php:38
‪TYPO3\CMS\Core\TimeTracker\TimeTracker
Definition: TimeTracker.php:30