Completed
Push — master ( abb405...0346f6 )
by
unknown
18:42 queued 02:27
created

FrontendRequestHandler::handleRequest()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 5
nop 0
dl 0
loc 23
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Extbase\Mvc\Web;
17
18
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
19
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
20
21
/**
22
 * A request handler which can handle web requests invoked by the frontend.
23
 * @internal only to be used within Extbase, not part of TYPO3 Core API.
24
 */
25
class FrontendRequestHandler extends AbstractRequestHandler
26
{
27
    /**
28
     * @var ConfigurationManagerInterface
29
     */
30
    protected $configurationManager;
31
32
    /**
33
     * @param ConfigurationManagerInterface $configurationManager
34
     */
35
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
36
    {
37
        $this->configurationManager = $configurationManager;
38
    }
39
40
    /**
41
     * Handles the web request. The response will automatically be sent to the client.
42
     *
43
     * @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface|null
44
     */
45
    public function handleRequest()
46
    {
47
        $request = $this->requestBuilder->build();
48
        if ($this->isActionCacheable($request->getControllerObjectName(), $request->getControllerActionName())) {
49
            $request->setIsCached(true);
50
        } else {
51
            $contentObject = $this->configurationManager->getContentObject();
52
            if ($contentObject->getUserObjectType() === ContentObjectRenderer::OBJECTTYPE_USER) {
0 ignored issues
show
introduced by
The condition $contentObject->getUserO...nderer::OBJECTTYPE_USER is always false.
Loading history...
53
                $contentObject->convertToUserIntObject();
54
                // \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::convertToUserIntObject() will recreate the object, so we have to stop the request here
55
                return null;
56
            }
57
            $request->setIsCached(false);
58
        }
59
60
        if ($this->configurationManager->isFeatureEnabled('requireCHashArgumentForActionArguments')) {
61
            trigger_error('The option requireCHashArgumentForActionArguments is removed', E_USER_DEPRECATED);
62
        }
63
64
        /** @var \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response */
65
        $response = $this->objectManager->get(Response::class);
66
        $this->dispatcher->dispatch($request, $response);
67
        return $response;
68
    }
69
70
    /**
71
     * This request handler can handle any web request.
72
     *
73
     * @return bool If the request is a web request, TRUE otherwise FALSE
74
     */
75
    public function canHandleRequest()
76
    {
77
        return $this->environmentService->isEnvironmentInFrontendMode();
78
    }
79
80
    protected function isActionCacheable(string $controllerClassName, string $actionName): bool
81
    {
82
        $frameworkConfiguration = $this->configurationManager->getConfiguration(
83
            ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK
84
        );
85
86
        $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerClassName]['nonCacheableActions'] ?? null;
87
88
        if (!is_array($nonCacheableActions)) {
89
            return true;
90
        }
91
92
        return !in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerClassName]['nonCacheableActions'], true);
93
    }
94
}
95