[~TAKS] Extbase (MVC): FrontendRequestHandler now retrieves the current cObject throu...
authorBastian Waidelich <bastian@typo3.org>
Mon, 15 Nov 2010 15:39:30 +0000 (15:39 +0000)
committerBastian Waidelich <bastian@typo3.org>
Mon, 15 Nov 2010 15:39:30 +0000 (15:39 +0000)
[+BUGFIX] Extbase (MVC): FrontendRequestHandler was refering to $this->frameworkConfiguration which wasn't available
[-API] Extbase (MVC): marked Tx_Extbase_MVC_Web_Request::getContentObjectData() deprecated as should retrieve the current cObject through the ConfigurationManager
[+TASK] Extbase (MVC): modified the Tx_Extbase_MVC_Web_RequestBuilder so that it's possible to change the action only by specifying the action parameter. Before you had to specify the controller as well, even if it was the default controller

typo3/sysext/extbase/Classes/Core/Bootstrap.php
typo3/sysext/extbase/Classes/MVC/RequestHandlerInterface.php
typo3/sysext/extbase/Classes/MVC/Web/AbstractRequestHandler.php
typo3/sysext/extbase/Classes/MVC/Web/FrontendRequestHandler.php
typo3/sysext/extbase/Classes/MVC/Web/Request.php
typo3/sysext/extbase/Classes/MVC/Web/RequestBuilder.php

index 98a97c7..ff14fba 100644 (file)
@@ -234,11 +234,18 @@ class Tx_Extbase_Core_Bootstrap {
 
                $requestHandlerResolver = $this->objectManager->get('Tx_Extbase_MVC_RequestHandlerResolver');
                $requestHandler = $requestHandlerResolver->resolveRequestHandler();
-               $requestHandler->setContentObject($this->cObj);
 
                $response = $requestHandler->handleRequest();
+
+               // If response is NULL after handling the request we need to stop
+               // This happens for instance, when a USER object was converted to a USER_INT
+               // @see Tx_Extbase_MVC_Web_FrontendRequestHandler::handleRequest()
+               if ($response === NULL) {
+                       $this->reflectionService->shutdown();
+                       return;
+               }
                if (count($response->getAdditionalHeaderData()) > 0) {
-                       $GLOBALS['TSFE']->additionalHeaderData[] = implode('', $response->getAdditionalHeaderData());
+                       $GLOBALS['TSFE']->additionalHeaderData[] = implode(chr(10), $response->getAdditionalHeaderData());
                }
                $response->sendHeaders();
                $content = $response->getContent();
index c5d6360..a51d727 100644 (file)
@@ -33,9 +33,9 @@
 interface Tx_Extbase_MVC_RequestHandlerInterface {
 
        /**
-        * Handles a raw request and sends the respsonse.
+        * Handles a raw request and returns the respsonse.
         *
-        * @return void
+        * @return Tx_Extbase_MVC_ResponseInterface
         * @api
         */
        public function handleRequest();
index 6881162..81628c5 100644 (file)
@@ -37,14 +37,6 @@ abstract class Tx_Extbase_MVC_Web_AbstractRequestHandler implements Tx_Extbase_M
        protected $objectManager;
 
        /**
-        * Back reference to the parent content object
-        * This has to be public as it is set directly from TYPO3
-        *
-        * @var tslib_cObj
-        */
-       protected $cObj;
-
-       /**
         * @var Tx_Extbase_MVC_Dispatcher
         */
        protected $dispatcher;
@@ -92,16 +84,6 @@ abstract class Tx_Extbase_MVC_Web_AbstractRequestHandler implements Tx_Extbase_M
        }
 
        /**
-        * Sets the content object
-        *
-        * @param tslib_cObj $cObj
-        * @return void
-        */
-       public function setContentObject(tslib_cObj $cObj = NULL) {
-               $this->cObj = $cObj;
-       }
-
-       /**
         * This request handler can handle any web request.
         *
         * @return boolean If the request is a web request, TRUE otherwise FALSE
index 4c0bb3f..456ab2b 100644 (file)
 class Tx_Extbase_MVC_Web_FrontendRequestHandler extends Tx_Extbase_MVC_Web_AbstractRequestHandler {
 
        /**
+        * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
+        */
+       protected $configurationManager;
+
+       /**
+        * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
+        * @return void
+        */
+       public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $configurationManager;
+       }
+
+       /**
         * Handles the web request. The response will automatically be sent to the client.
         *
         * @return Tx_Extbase_MVC_Web_Response
@@ -43,19 +56,16 @@ class Tx_Extbase_MVC_Web_FrontendRequestHandler extends Tx_Extbase_MVC_Web_Abstr
                $requestHashService = $this->objectManager->get('Tx_Extbase_Security_Channel_RequestHashService'); // singleton
                $requestHashService->verifyRequest($request);
 
-               if (isset($this->cObj->data) && is_array($this->cObj->data)) {
-                       // we need to check the above conditions as cObj is not available in Backend.
-                       $request->setContentObjectData($this->cObj->data);
-                       if ($this->isCacheable($request->getControllerName(), $request->getControllerActionName())) {
-                               $request->setIsCached(TRUE);
-                       } else {
-                               if ($this->cObj->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
-                                       $this->cObj->convertToUserIntObject();
-                                       // tslib_cObj::convertToUserIntObject() will recreate the object, so we have to stop the request here
-                                       return;
-                               }
-                               $request->setIsCached(FALSE);
+               if ($this->isCacheable($request->getControllerName(), $request->getControllerActionName())) {
+                       $request->setIsCached(TRUE);
+               } else {
+                       $contentObject = $this->configurationManager->getContentObject();
+                       if ($contentObject->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
+                               $contentObject->convertToUserIntObject();
+                               // tslib_cObj::convertToUserIntObject() will recreate the object, so we have to stop the request here
+                               return;
                        }
+                       $request->setIsCached(FALSE);
                }
                $response = $this->objectManager->create('Tx_Extbase_MVC_Web_Response');
 
@@ -81,8 +91,9 @@ class Tx_Extbase_MVC_Web_FrontendRequestHandler extends Tx_Extbase_MVC_Web_Abstr
         * @return boolean TRUE if the given action should be cached, otherwise FALSE
         */
        protected function isCacheable($controllerName, $actionName) {
-               if (isset($this->frameworkConfiguration['switchableControllerActions'][$controllerName]['nonCacheableActions'])
-                       && in_array($actionName, t3lib_div::trimExplode(',', $this->frameworkConfiguration['switchableControllerActions'][$controllerName]['nonCacheableActions']))) {
+               $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
+               if (isset($frameworkConfiguration['switchableControllerActions'][$controllerName]['nonCacheableActions'])
+                       && in_array($actionName, t3lib_div::trimExplode(',', $frameworkConfiguration['switchableControllerActions'][$controllerName]['nonCacheableActions']))) {
                                return FALSE;
                        }
                return TRUE;
index 6768bbb..106bfb6 100644 (file)
@@ -63,14 +63,22 @@ class Tx_Extbase_MVC_Web_Request extends Tx_Extbase_MVC_Request {
        protected $hmacVerified = FALSE;
 
        /**
-        * @var array data of the current cObj
+        * @var boolean TRUE if the current request is cached, false otherwise.
         */
-       protected $contentObjectData = array();
+       protected $isCached = FALSE;
 
        /**
-        * @var boolean TRUE if the current request is cached, false otherwise.
+        * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
         */
-       protected $isCached = FALSE;
+       protected $configurationManager;
+
+       /**
+        * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
+        * @return void
+        */
+       public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $configurationManager;
+       }
 
        /**
         * Sets the request method
@@ -160,38 +168,29 @@ class Tx_Extbase_MVC_Web_Request extends Tx_Extbase_MVC_Request {
        }
 
        /**
-        * Sets the data array of the current content object
-        *
-        * @param array $contentObjectData data of the current cObj
-        * @return void
-        * @author Bastian Waidelich <bastian@typo3.org>
-        */
-       public function setContentObjectData(array $contentObjectData) {
-               $this->contentObjectData = $contentObjectData;
-       }
-
-       /**
         * Returns the data array of the current content object
         *
         * @return array data of the current cObj
-        * @api (v4 only)
+        * @deprecated since Extbase 1.3.0; will be removed in Extbase 1.5.0. Use the ConfigurationManager to retrieve the current ContentObject
         * @author Bastian Waidelich <bastian@typo3.org>
         */
        public function getContentObjectData() {
-               return $this->contentObjectData;
+               t3lib_div::logDeprecatedFunction();
+               $contentObject = $this->configurationManager->getContentObject();
+               return $contentObject->data;
        }
-       
+
        /**
         * Set if the current request is cached.
-        * 
+        *
         * @param boolean $isCached
         */
        public function setIsCached($isCached) {
                $this->isCached = (boolean) $isCached;
-       } 
+       }
        /**
         * Return whether the current request is a cached request or not.
-        * 
+        *
         * @api (v4 only)
         * @return boolean the caching status.
         */
index ac5fa03..7d5c99d 100644 (file)
@@ -144,14 +144,13 @@ class Tx_Extbase_MVC_Web_RequestBuilder implements t3lib_Singleton {
 
                if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions)) {
                        $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING);
-                       $allowedActions = $this->allowedControllerActions[$controllerName];
-                       if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
-                               $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
-                       } else {
-                               $actionName = $this->defaultActionName;
-                       }
                } else {
                        $controllerName = $this->defaultControllerName;
+               }
+               $allowedActions = $this->allowedControllerActions[$controllerName];
+               if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
+                       $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
+               } else {
                        $actionName = $this->defaultActionName;
                }