15eecced2855d76339fc0aa23643348b041a7211
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / Web / FrontendRequestHandler.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * A request handler which can handle web requests invoked by the frontend.
30 *
31 */
32 class Tx_Extbase_MVC_Web_FrontendRequestHandler extends Tx_Extbase_MVC_Web_AbstractRequestHandler {
33
34 /**
35 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
36 */
37 protected $configurationManager;
38
39 /**
40 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
41 * @return void
42 */
43 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
44 $this->configurationManager = $configurationManager;
45 }
46
47 /**
48 * Handles the web request. The response will automatically be sent to the client.
49 *
50 * @return Tx_Extbase_MVC_Web_Response
51 */
52 public function handleRequest() {
53 $request = $this->requestBuilder->build();
54
55 // Request hash service
56 $requestHashService = $this->objectManager->get('Tx_Extbase_Security_Channel_RequestHashService'); // singleton
57 $requestHashService->verifyRequest($request);
58
59 if ($this->isCacheable($request->getControllerName(), $request->getControllerActionName())) {
60 $request->setIsCached(TRUE);
61 } else {
62 $contentObject = $this->configurationManager->getContentObject();
63 if ($contentObject->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
64 $contentObject->convertToUserIntObject();
65 // tslib_cObj::convertToUserIntObject() will recreate the object, so we have to stop the request here
66 return;
67 }
68 $request->setIsCached(FALSE);
69 }
70 $response = $this->objectManager->create('Tx_Extbase_MVC_Web_Response');
71
72 $this->dispatcher->dispatch($request, $response);
73
74 return $response;
75 }
76
77 /**
78 * This request handler can handle any web request.
79 *
80 * @return boolean If the request is a web request, TRUE otherwise FALSE
81 */
82 public function canHandleRequest() {
83 return TYPO3_MODE === 'FE';
84 }
85
86 /**
87 * Determines whether the current action can be cached
88 *
89 * @param string $controllerName
90 * @param string $actionName
91 * @return boolean TRUE if the given action should be cached, otherwise FALSE
92 */
93 protected function isCacheable($controllerName, $actionName) {
94 $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
95 if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])
96 && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
97 return FALSE;
98 }
99 return TRUE;
100 }
101
102 }
103 ?>