24fb844fe153512e959913e616a84dc9aaa6877f
[Packages/TYPO3.CMS.git] / typo3 / sysext / adminpanel / Classes / Middleware / AdminPanelDataPersister.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Adminpanel\Middleware;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
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.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Server\MiddlewareInterface;
22 use Psr\Http\Server\RequestHandlerInterface;
23 use TYPO3\CMS\Adminpanel\Controller\MainController;
24 use TYPO3\CMS\Adminpanel\Utility\StateUtility;
25 use TYPO3\CMS\Core\Http\NullResponse;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
28
29 /**
30 * Store request data of current request in cache for rendering in admin panel
31 *
32 * @internal
33 */
34 class AdminPanelDataPersister implements MiddlewareInterface
35 {
36 /**
37 * Render the admin panel if activated
38 */
39 public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
40 {
41 $response = $handler->handle($request);
42 if (
43 !($response instanceof NullResponse)
44 && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
45 && $GLOBALS['TSFE']->isOutputting()
46 && StateUtility::isActivatedForUser()
47 && StateUtility::isActivatedInTypoScript()
48 && !StateUtility::isHiddenForUser()
49 ) {
50 $mainController = GeneralUtility::makeInstance(MainController::class);
51 $mainController->storeData($request);
52 }
53 return $response;
54 }
55 }