[+FEATURE] Extbase (MVC): Created isCached property for the request (Resolves #7937)
authorSebastian Kurfürst <sebastian@typo3.org>
Fri, 28 May 2010 06:54:55 +0000 (06:54 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Fri, 28 May 2010 06:54:55 +0000 (06:54 +0000)
typo3/sysext/extbase/Classes/Dispatcher.php
typo3/sysext/extbase/Classes/MVC/Web/Request.php
typo3/sysext/extbase/Tests/MVC/Web/RequestTest.php [new file with mode: 0644]

index 4d051e3..bce85c6 100644 (file)
@@ -112,6 +112,7 @@ class Tx_Extbase_Dispatcher {
                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);
+                       $request->setIsCached($this->cObj->getUserObjectType() == tslib_cObj::OBJECTTYPE_USER);
                }
                $response = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Response');
 
index 1c41d8b..6768bbb 100755 (executable)
@@ -68,6 +68,11 @@ class Tx_Extbase_MVC_Web_Request extends Tx_Extbase_MVC_Request {
        protected $contentObjectData = array();
 
        /**
+        * @var boolean TRUE if the current request is cached, false otherwise.
+        */
+       protected $isCached = FALSE;
+
+       /**
         * Sets the request method
         *
         * @param string $method Name of the request method
@@ -175,5 +180,23 @@ class Tx_Extbase_MVC_Web_Request extends Tx_Extbase_MVC_Request {
        public function getContentObjectData() {
                return $this->contentObjectData;
        }
+       
+       /**
+        * 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.
+        */
+       public function isCached() {
+               return $this->isCached;
+       }
 }
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/MVC/Web/RequestTest.php b/typo3/sysext/extbase/Tests/MVC/Web/RequestTest.php
new file mode 100644 (file)
index 0000000..f18ae1d
--- /dev/null
@@ -0,0 +1,46 @@
+<?php 
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2010 Sebastian Kurfuerst <sebastian@typo3.org>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+class Tx_Extbase_MVC_Web_RequestTest extends Tx_Extbase_BaseTestCase {
+       /**
+        * @test
+        */
+       public function isCachedReturnsFalseByDefault() {
+               $request = new Tx_Extbase_MVC_Web_Request();
+               $this->assertFalse($request->isCached());
+       }
+
+       /**
+        * @test
+        */
+       public function isCachedReturnsTheValueWhichWasPreviouslySet() {
+               $request = new Tx_Extbase_MVC_Web_Request();
+               $request->setIsCached(TRUE);
+               $this->assertTrue($request->isCached());
+       }
+}
+?>
\ No newline at end of file