Files
gutachten_t3/typo3/sysext/adminpanel/Classes/Middleware/AdminPanelRenderer.php
T
2026-10-19 08:18:39 +02:00

71 lines
2.3 KiB
PHP

<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Adminpanel\Middleware;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Adminpanel\Controller\MainController;
use TYPO3\CMS\Adminpanel\Utility\StateUtility;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Render the admin panel via PSR-15 middleware
*
* @internal
*/
class AdminPanelRenderer implements MiddlewareInterface
{
/**
* Render the admin panel if activated
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if (
!($response instanceof NullResponse)
&& $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
&& $GLOBALS['TSFE']->isOutputting()
&& StateUtility::isActivatedForUser()
&& StateUtility::isActivatedInTypoScript()
&& !StateUtility::isHiddenForUser()
) {
$mainController = GeneralUtility::makeInstance(MainController::class);
$body = $response->getBody();
$body->rewind();
$contents = $response->getBody()->getContents();
$content = str_ireplace(
'</body>',
$mainController->render($request) . '</body>',
$contents
);
$body = new Stream('php://temp', 'rw');
$body->write($content);
$response = $response->withBody($body);
}
return $response;
}
}