2 declare(strict_types
= 1);
4 namespace TYPO3\CMS\Frontend\Middleware
;
7 * This file is part of the TYPO3 CMS project.
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
16 * The TYPO3 project - inspiring people to share!
19 use Psr\Http\Message\ResponseInterface
;
20 use Psr\Http\Message\ServerRequestInterface
;
21 use Psr\Http\Server\MiddlewareInterface
;
22 use Psr\Http\Server\RequestHandlerInterface
as PsrRequestHandlerInterface
;
23 use TYPO3\CMS\Core\TimeTracker\TimeTracker
;
24 use TYPO3\CMS\Core\Utility\GeneralUtility
;
25 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
28 * Initialization of TypoScriptFrontendController
30 * Do all necessary preparation steps for rendering
32 class PrepareTypoScriptFrontendRendering
implements MiddlewareInterface
35 * @var TypoScriptFrontendController
37 protected $controller;
42 protected $timeTracker;
44 public function __construct(TypoScriptFrontendController
$controller = null, TimeTracker
$timeTracker = null)
46 $this->controller
= $controller ?
: $GLOBALS['TSFE'];
47 $this->timeTracker
= $timeTracker ?
: GeneralUtility
::makeInstance(TimeTracker
::class);
51 * Initialize TypoScriptFrontendController to the point right before rendering of the page is triggered
53 * @param ServerRequestInterface $request
54 * @param PsrRequestHandlerInterface $handler
55 * @return ResponseInterface
57 public function process(ServerRequestInterface
$request, PsrRequestHandlerInterface
$handler): ResponseInterface
59 // Starts the template
60 $this->timeTracker
->push('Start Template');
61 $this->controller
->initTemplate();
62 $this->timeTracker
->pull();
64 $this->timeTracker
->push('Get Page from cache');
65 // Locks may be acquired here
66 $this->controller
->getFromCache();
67 $this->timeTracker
->pull();
68 // Get config if not already gotten
69 // After this, we should have a valid config-array ready
70 $this->controller
->getConfigArray();
71 // Setting language and locale
72 $this->timeTracker
->push('Setting language and locale');
73 $this->controller
->settingLanguage();
74 $this->controller
->settingLocale();
75 $this->timeTracker
->pull();
77 // Convert POST data to utf-8 for internal processing if metaCharset is different
78 $this->controller
->convPOSTCharset();
80 $this->controller
->initializeRedirectUrlHandlers();
81 $this->controller
->handleDataSubmission();
83 return $handler->handle($request);