first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user