From 06092ea848d6024c299a04b5b1e2ae8fb6328714 Mon Sep 17 00:00:00 2001 From: Helmut Hummel Date: Tue, 1 May 2018 14:19:33 +0200 Subject: [PATCH] [TASK] Move page rendering preparations into middleware In the course of making TSFE request/response aware, we split the rendering preparations of TSFE into a PSR-15 middleware. This the first step to extract other parts, like redirecting to shortcuts/ mountpoints and sending http headers as well into middleware implementations. Resolves: #84909 Releases: master Change-Id: I704ae89a23c8e254574e19a78ecec363f182c747 Reviewed-on: https://review.typo3.org/56833 Tested-by: TYPO3com Reviewed-by: Georg Ringer Tested-by: Georg Ringer Reviewed-by: Frank Naegler Tested-by: Frank Naegler --- .../frontend/Classes/Http/RequestHandler.php | 24 ------ .../PrepareTypoScriptFrontendRendering.php | 84 +++++++++++++++++++ .../Configuration/RequestMiddlewares.php | 6 ++ .../Configuration/RequestMiddlewares.php | 3 + 4 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index bff3d7c30c39..044d0ddddc47 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -68,30 +68,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface /** @var TypoScriptFrontendController $controller */ $controller = $GLOBALS['TSFE']; - // Starts the template - $this->timeTracker->push('Start Template', ''); - $controller->initTemplate(); - $this->timeTracker->pull(); - // Get from cache - $this->timeTracker->push('Get Page from cache', ''); - $controller->getFromCache(); - $this->timeTracker->pull(); - // Get config if not already gotten - // After this, we should have a valid config-array ready - $controller->getConfigArray(); - // Setting language and locale - $this->timeTracker->push('Setting language and locale', ''); - $controller->settingLanguage(); - $controller->settingLocale(); - $this->timeTracker->pull(); - - // Convert POST data to utf-8 for internal processing if metaCharset is different - $controller->convPOSTCharset(); - - $controller->initializeRedirectUrlHandlers(); - - $controller->handleDataSubmission(); - // Check for shortcut page and redirect $controller->checkPageForShortcutRedirect(); $controller->checkPageForMountpointRedirect(); diff --git a/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php b/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php new file mode 100644 index 000000000000..fccdaa450b18 --- /dev/null +++ b/typo3/sysext/frontend/Classes/Middleware/PrepareTypoScriptFrontendRendering.php @@ -0,0 +1,84 @@ +controller = $controller ?: $GLOBALS['TSFE']; + $this->timeTracker = $timeTracker ?: GeneralUtility::makeInstance(TimeTracker::class); + } + + /** + * Initialize TypoScriptFrontendController to the point right before rendering of the page is triggered + * + * @param ServerRequestInterface $request + * @param PsrRequestHandlerInterface $handler + * @return ResponseInterface + */ + public function process(ServerRequestInterface $request, PsrRequestHandlerInterface $handler): ResponseInterface + { + // Starts the template + $this->timeTracker->push('Start Template', ''); + $this->controller->initTemplate(); + $this->timeTracker->pull(); + // Get from cache + $this->timeTracker->push('Get Page from cache', ''); + $this->controller->getFromCache(); + $this->timeTracker->pull(); + // Get config if not already gotten + // After this, we should have a valid config-array ready + $this->controller->getConfigArray(); + // Setting language and locale + $this->timeTracker->push('Setting language and locale', ''); + $this->controller->settingLanguage(); + $this->controller->settingLocale(); + $this->timeTracker->pull(); + + // Convert POST data to utf-8 for internal processing if metaCharset is different + $this->controller->convPOSTCharset(); + + $this->controller->initializeRedirectUrlHandlers(); + $this->controller->handleDataSubmission(); + + return $handler->handle($request); + } +} diff --git a/typo3/sysext/frontend/Configuration/RequestMiddlewares.php b/typo3/sysext/frontend/Configuration/RequestMiddlewares.php index e69552eea4eb..4912d28c8980 100644 --- a/typo3/sysext/frontend/Configuration/RequestMiddlewares.php +++ b/typo3/sysext/frontend/Configuration/RequestMiddlewares.php @@ -90,5 +90,11 @@ 'typo3/cms-frontend/site', ] ], + 'typo3/cms-frontend/prepare-tsfe-rendering' => [ + 'target' => \TYPO3\CMS\Frontend\Middleware\PrepareTypoScriptFrontendRendering::class, + 'after' => [ + 'typo3/cms-frontend/page-resolver', + ] + ], ] ]; diff --git a/typo3/sysext/redirects/Configuration/RequestMiddlewares.php b/typo3/sysext/redirects/Configuration/RequestMiddlewares.php index 42387d1c4f85..9ac677920947 100644 --- a/typo3/sysext/redirects/Configuration/RequestMiddlewares.php +++ b/typo3/sysext/redirects/Configuration/RequestMiddlewares.php @@ -7,6 +7,9 @@ 'frontend' => [ 'typo3/cms-redirects/redirecthandler' => [ 'target' => \TYPO3\CMS\Redirects\Http\Middleware\RedirectHandler::class, + 'before' => [ + 'typo3/cms-frontend/prepare-tsfe-rendering', + ] ], ], ];