2 declare(strict_types
= 1);
4 namespace TYPO3\CMS\Adminpanel\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
;
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\Http\Stream
;
27 use TYPO3\CMS\Core\Utility\GeneralUtility
;
28 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
31 * Render the admin panel via PSR-15 middleware
35 class AdminPanelRenderer
implements MiddlewareInterface
39 * Render the admin panel if activated
40 * @param ServerRequestInterface $request
41 * @param RequestHandlerInterface $handler
42 * @return ResponseInterface
44 public function process(ServerRequestInterface
$request, RequestHandlerInterface
$handler): ResponseInterface
46 $response = $handler->handle($request);
48 !($response instanceof NullResponse
)
49 && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
50 && $GLOBALS['TSFE']->isOutputting()
51 && StateUtility
::isActivatedForUser()
52 && StateUtility
::isActivatedInTypoScript()
53 && !StateUtility
::isHiddenForUser()
55 $mainController = GeneralUtility
::makeInstance(MainController
::class);
56 $body = $response->getBody();
58 $contents = $response->getBody()->getContents();
59 $content = str_ireplace(
61 $mainController->render($request) . '</body>',
64 $body = new Stream('php://temp', 'rw');
65 $body->write($content);
66 $response = $response->withBody($body);