TYPO3 API  SVNRelease
FrontendRequestHandler.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
00006  *  All rights reserved
00007  *
00008  *  This class is a backport of the corresponding class of FLOW3.
00009  *  All credits go to the v5 team.
00010  *
00011  *  This script is part of the TYPO3 project. The TYPO3 project is
00012  *  free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; either version 2 of the License, or
00015  *  (at your option) any later version.
00016  *
00017  *  The GNU General Public License can be found at
00018  *  http://www.gnu.org/copyleft/gpl.html.
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * A request handler which can handle web requests invoked by the frontend.
00030  *
00031  */
00032 class Tx_Extbase_MVC_Web_FrontendRequestHandler extends Tx_Extbase_MVC_Web_AbstractRequestHandler {
00033 
00034     /**
00035      * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
00036      */
00037     protected $configurationManager;
00038 
00039     /**
00040      * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
00041      * @return void
00042      */
00043     public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
00044         $this->configurationManager = $configurationManager;
00045     }
00046 
00047     /**
00048      * Handles the web request. The response will automatically be sent to the client.
00049      *
00050      * @return Tx_Extbase_MVC_Web_Response
00051      */
00052     public function handleRequest() {
00053         $request = $this->requestBuilder->build();
00054 
00055         // Request hash service
00056         $requestHashService = $this->objectManager->get('Tx_Extbase_Security_Channel_RequestHashService'); // singleton
00057         $requestHashService->verifyRequest($request);
00058 
00059         if ($this->isCacheable($request->getControllerName(), $request->getControllerActionName())) {
00060             $request->setIsCached(TRUE);
00061         } else {
00062             $contentObject = $this->configurationManager->getContentObject();
00063             if ($contentObject->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
00064                 $contentObject->convertToUserIntObject();
00065                 // tslib_cObj::convertToUserIntObject() will recreate the object, so we have to stop the request here
00066                 return;
00067             }
00068             $request->setIsCached(FALSE);
00069         }
00070         $response = $this->objectManager->create('Tx_Extbase_MVC_Web_Response');
00071 
00072         $this->dispatcher->dispatch($request, $response);
00073 
00074         return $response;
00075     }
00076 
00077     /**
00078      * This request handler can handle any web request.
00079      *
00080      * @return boolean If the request is a web request, TRUE otherwise FALSE
00081      */
00082     public function canHandleRequest() {
00083         return TYPO3_MODE === 'FE';
00084     }
00085 
00086     /**
00087      * Determines whether the current action can be cached
00088      *
00089      * @param string $controllerName
00090      * @param string $actionName
00091      * @return boolean TRUE if the given action should be cached, otherwise FALSE
00092      */
00093     protected function isCacheable($controllerName, $actionName) {
00094         $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
00095         if (isset($frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])
00096             && in_array($actionName, $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'])) {
00097                 return FALSE;
00098             }
00099         return TRUE;
00100     }
00101 
00102 }
00103 ?>