Completed
Branch master (d17104)
by Christian
21:20
created

AdminPanelDataPersister   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 15 7
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
     * @param ServerRequestInterface $request
39
     * @param RequestHandlerInterface $handler
40
     * @return ResponseInterface
41
     */
42
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
43
    {
44
        $response = $handler->handle($request);
45
        if (
46
            !($response instanceof NullResponse)
47
            && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
48
            && $GLOBALS['TSFE']->isOutputting()
49
            && StateUtility::isActivatedForUser()
50
            && StateUtility::isActivatedInTypoScript()
51
            && !StateUtility::isHiddenForUser()
52
        ) {
53
            $mainController = GeneralUtility::makeInstance(MainController::class);
54
            $mainController->storeData($request);
55
        }
56
        return $response;
57
    }
58
}
59