EXTMVC:
authorJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 14:53:52 +0000 (14:53 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 14:53:52 +0000 (14:53 +0000)
* Refactored Validation
* Fixed caching

22 files changed:
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_AbstractController.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_ActionController.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_Argument.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_Arguments.php
typo3/sysext/extbase/Classes/Persistence/Mapper/TX_EXTMVC_Persistence_Mapper_DataMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper.php
typo3/sysext/extbase/Classes/Persistence/TX_EXTMVC_Persistence_Repository.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_EmailAddress.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_Float.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_Integer.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_NotEmpty.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_Number.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_NumberRange.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_RegularExpression.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_Text.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_UUID.php [deleted file]
typo3/sysext/extbase/Classes/View/Helper/TX_EXTMVC_View_Helper_LinkHelper.php
typo3/sysext/extbase/Classes/View/Helper/TX_EXTMVC_View_Helper_TranslateHelper.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_AbstractView.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_EmptyView.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_TemplateView.php
typo3/sysext/extbase/class.tx_extmvc_dispatcher.php

index bfea337..3480f20 100755 (executable)
@@ -59,6 +59,12 @@ abstract class TX_EXTMVC_Controller_AbstractController implements TX_EXTMVC_Cont
         */
        protected $arguments;
        
+       /**
+        * Actions that schould not be cached (changes the invocated dispatcher to a USER_INT cObject)
+        * @var array
+        */
+       protected $nonCachableActions = array();
+       
        /**
         * Constructs the controller.
         *
@@ -96,6 +102,11 @@ abstract class TX_EXTMVC_Controller_AbstractController implements TX_EXTMVC_Cont
                $this->mapRequestArgumentsToLocalArguments();
        }
        
+       public function isCachableAction($action) {
+               if (in_array($action, $this->nonCachableActions)) return FALSE;
+               return TRUE;
+       }
+       
        /**
         * Initializes (registers / defines) arguments of this controller.
         *
index bb46723..0190a51 100644 (file)
@@ -60,12 +60,6 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
         */
        protected $actionMethodName = 'indexAction';
        
-       /**
-        * Actions that schould not be cached (changes the invocated dispatcher to a USER_INT cObject)
-        * @var array
-        */
-       protected $nonCachableActions = array();
-
        /**
         * Handles a request. The result output is returned by altering the given response.
         *
@@ -83,13 +77,9 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
                $this->mapRequestArgumentsToLocalArguments();
                if ($this->initializeView) $this->initializeView();
                $this->initializeAction();
-
                $this->callActionMethod();
-               if (in_array($this->request->getControllerActionName(), $this->nonCachableActions)) {
-                       throw new TX_EXTMVC_Exception_StopUncachedAction();
-               }
        }
-
+       
        /**
         * Determines the action method and assures that the method exists.
         *
@@ -111,12 +101,7 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
         * @return void
         */
        protected function callActionMethod() {
-               $preparedArguments = array();
-               // foreach ($this->arguments as $argument) {
-               //      $preparedArguments[] = $argument->getValue();
-               // }
-
-               $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
+               $actionResult = call_user_func_array(array($this, $this->actionMethodName), array());
                if ($actionResult === NULL && $this->view instanceof TX_EXTMVC_View_ViewInterface) {
                        $this->response->appendContent($this->view->render());
                } elseif (is_string($actionResult) && strlen($actionResult) > 0) {
index 12f0084..02cd7c8 100644 (file)
@@ -20,6 +20,9 @@
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/TX_EXTMVC_Validation_Errors.php');
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ChainValidator.php');
+
 /**
  * A controller argument
  *
@@ -99,7 +102,11 @@ class TX_EXTMVC_Controller_Argument {
        public function __construct($name, $dataType = 'Text') {
                if (!is_string($name) || strlen($name) < 1) throw new InvalidArgumentException('$name must be of type string, ' . gettype($name) . ' given.', 1187951688);
                $this->name = $name;
-               $this->setDataType($dataType);
+               if (is_array($dataType)) {
+                       $this->setNewValidatorChain($dataType);
+               } else {
+                       $this->setDataType($dataType);
+               }
        }
 
        /**
@@ -141,6 +148,7 @@ class TX_EXTMVC_Controller_Argument {
         */
        public function setDataType($dataType) {
                $this->dataType = ($dataType != '' ? $dataType : 'Text');
+               // TODO Make validator path and class names configurable
                $dataTypeValidatorClassName = 'TX_EXTMVC_Validation_Validator_' . $this->dataType;
                $classFilePathAndName = t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/' . $dataTypeValidatorClassName . '.php';
                if (isset($classFilePathAndName) && file_exists($classFilePathAndName)) {                       
@@ -294,6 +302,26 @@ class TX_EXTMVC_Controller_Argument {
                return $this->datatypeValidator;
        }
        
+       /**
+        * Create and set a validator chain
+        *
+        * @param array Object names of the validators
+        * @return TX_EXTMVC_MVC_Controller_Argument Returns $this (used for fluent interface)
+        */
+       public function setNewValidatorChain(array $validators) {
+               $this->validator = t3lib_div::makeInstance('TX_EXTMVC_Validation_Validator_ChainValidator');
+               foreach ($validators as $validator) {
+                       if (is_array($validator)) {
+                               $objectName = 'TX_EXTMVC_Validation_Validator_' . $validator[0];
+                               $this->validator->addValidator(new $objectName);
+                       } else {
+                               $objectName = 'TX_EXTMVC_Validation_Validator_' . $validator;
+                               $this->validator->addValidator(t3lib_div::makeInstance($objectName));
+                       }
+               }
+               return $this;
+       }
+       
        /**
         * Set the uid for the argument.
         *
index c2becdf..3d949c9 100644 (file)
@@ -110,16 +110,13 @@ class TX_EXTMVC_Controller_Arguments extends ArrayObject {
         * If an argument with the same name exists already, it will be replaced by the
         * new argument object.
         *
-        * If $dataType is an object registered at the Object Manager, it sets the default property converter to map this property.
-        *
         * @param string $name Name of the argument
         * @param string $dataType Name of one of the built-in data types
         * @param boolean $isRequired TRUE if this argument should be marked as required
         * @return TX_EXTMVC_Controller_Argument The new argument
         */
        public function addNewArgument($name, $dataType = 'Text', $isRequired = FALSE) {
-               $argumentClassName = t3lib_div::makeInstanceClassName('TX_EXTMVC_Controller_Argument');
-               $argument = new $argumentClassName($name, $dataType);
+               $argument = new TX_EXTMVC_Controller_Argument($name, $dataType);
                $argument->setRequired($isRequired);
                $this->addArgument($argument);
                return $argument;
index d331d6d..f321f3f 100644 (file)
@@ -78,9 +78,8 @@ class TX_EXTMVC_Persistence_Mapper_DataMap {
                $columns = $GLOBALS['TCA'][$this->getTableName()]['columns'];
                if (is_array($columns)) {
                        $this->addCommonColumns();                      
-                       $columnMapClassName = t3lib_div::makeInstanceClassName('TX_EXTMVC_Persistence_Mapper_ColumnMap');                       
                        foreach ($columns as $columnName => $columnConfiguration) {
-                               $columnMap = new $columnMapClassName($columnName, $this);
+                               $columnMap = new TX_EXTMVC_Persistence_Mapper_ColumnMap($columnName, $this);
                                $this->setTypeOfValue($columnMap, $columnConfiguration);
                                // TODO support for IRRE
                                // TODO support for MM_insert_fields and MM_match_fields
@@ -149,8 +148,7 @@ class TX_EXTMVC_Persistence_Mapper_DataMap {
        }
        
        public function addColumn($columnName, $typeOfValue = TX_EXTMVC_Persistence_Mapper_ColumnMap::TYPE_STRING, $typeOfRelation = TX_EXTMVC_Persistence_Mapper_ColumnMap::RELATION_NONE) {
-               $columnMapClassName = t3lib_div::makeInstanceClassName('TX_EXTMVC_Persistence_Mapper_ColumnMap');
-               $columnMap = new $columnMapClassName($columnName);
+               $columnMap = new TX_EXTMVC_Persistence_Mapper_ColumnMap($columnName);
                $columnMap->setTypeOfValue($typeOfValue);
                $columnMap->setTypeOfRelation($typeOfRelation);
                $this->addColumnMap($columnMap);
index d6070c8..790283b 100644 (file)
@@ -21,6 +21,7 @@
  *                                                                        */
 
 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
+require_once(PATH_tslib . 'class.tslib_content.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Utility/TX_EXTMVC_Utility_Strings.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/TX_EXTMVC_Persistence_ObjectStorage.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/Mapper/TX_EXTMVC_Persistence_Mapper_DataMap.php');
@@ -47,6 +48,13 @@ class TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Singl
         **/
        protected $session;
                
+       /**
+        * Cached data maps
+        *
+        * @var array
+        **/
+       protected $dataMaps = array();
+               
        /**
         * Constructs a new mapper
         *
@@ -473,8 +481,7 @@ class TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Singl
         * @return boolean TRUE if the property is persistable (configured in $TCA)
         */             
        public function isPersistableProperty($className, $propertyName) {
-               $dataMapClassName = t3lib_div::makeInstanceClassName('TX_EXTMVC_Persistence_Mapper_DataMap');
-               $dataMap = new $dataMapClassName($className);
+               $dataMap = new TX_EXTMVC_Persistence_Mapper_DataMap($className);
                $dataMap->initialize();
                return $dataMap->isPersistableProperty($propertyName);
        }
@@ -485,11 +492,13 @@ class TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Singl
         * @return TX_EXTMVC_Persistence_Mapper_DataMap The data map
         */
        protected function getDataMap($className) {
-               $dataMapClassName = t3lib_div::makeInstanceClassName('TX_EXTMVC_Persistence_Mapper_DataMap');
                // TODO Cache data maps
-               $dataMap = new $dataMapClassName($className);
-               $dataMap->initialize();
-               return $dataMap;
+               if (empty($this->dataMaps[$className])) {
+                       $dataMap = new TX_EXTMVC_Persistence_Mapper_DataMap($className);
+                       $dataMap->initialize();
+                       $this->dataMaps[$className] = $dataMap;
+               }
+               return $this->dataMaps[$className];
        }
        
 }
index d5ef929..9bf4331 100644 (file)
@@ -21,6 +21,7 @@
  *                                                                        */
 
 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
+require_once(PATH_tslib . 'class.tslib_content.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Utility/TX_EXTMVC_Utility_Strings.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/TX_EXTMVC_Persistence_ObjectStorage.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/TX_EXTMVC_Persistence_RepositoryInterface.php');
index f4ce418..9bfc73e 100644 (file)
@@ -31,7 +31,8 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_EmailAddress implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given property ($proptertyValue) is a valid email address.
+        * Checks if the given value is a valid email address.
+        *
         * Any errors will be stored in the given errors object.
         * If at least one error occurred, the result is FALSE.
         *
index 0cbc2bf..2332878 100644 (file)
@@ -31,9 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_Float implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is a valid float.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * Checks if the given value is a valid float.
+        *
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
@@ -41,8 +42,9 @@ class TX_EXTMVC_Validation_Validator_Float implements TX_EXTMVC_Validation_Valid
         * @return boolean TRUE if the value is valid, FALSE if an error occured
         */
        public function isValid($value, TX_EXTMVC_Validation_Errors &$errors, array $validationOptions = array()) {
-               if (is_float($value)) return TRUE;
-               if (is_string($value) && strpos($value, '.') && preg_match('/^[0-9.e+-]+$/', $value)) return TRUE;
+               if (is_float($value) || (is_string($value) && strpos($value, '.') !== FALSE && preg_match('/^[0-9.e+-]+$/', $value))) {
+                       return TRUE;
+               }
                $errors->append('The given subject was not a valid float.');
                return FALSE;
        }
index d1e47d9..9b88646 100644 (file)
@@ -31,9 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_Integer implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is a valid integer.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * Checks if the given value is a valid integer.
+        *
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
index e8c837f..5eb6983 100644 (file)
@@ -31,9 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_NotEmpty implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is not empty (NULL or empty string).
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * Checks if the given property ($propertyValue) is not empty (NULL or empty string).
+        *
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
index 310fe64..d751820 100644 (file)
@@ -31,9 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_Number implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is a valid number.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * Checks if the given value is a valid number.
+        *
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
index b967e54..983163e 100644 (file)
@@ -31,37 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_NumberRange implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * The start value of the range
-        * @var number
-        */
-       protected $startRange;
-
-       /**
-        * The end value of the range
-        * @var number
-        */
-       protected $endRange;
-
-       /**
-        * Constructor
+        * Returns TRUE, if the given property ($propertyValue) is a valid number in the given range.
         *
-        * @param number The start of the range
-        * @param number The end of the range
-        */
-       public function __construct($startRange, $endRange) {
-               if ($startRange > $endRange) {
-                       $this->endRange = $startRange;
-                       $this->startRange = $endRange;
-               } else {
-                       $this->endRange = $endRange;
-                       $this->startRange = $startRange;
-               }
-       }
-
-       /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is a valid number in the given range.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
@@ -69,10 +42,22 @@ class TX_EXTMVC_Validation_Validator_NumberRange implements TX_EXTMVC_Validation
         * @return boolean TRUE if the value is valid, FALSE if an error occured
         */
        public function isValid($value, TX_EXTMVC_Validation_Errors &$errors, array $validationOptions = array()) {
-               if (!is_numeric($value)) $errors->append('The given subject was not a valid number.');
-               if ($value < $this->startRange || $value > $this->endRange) $errors->append('The given subject was not in the valid range (' . $this->startRange . ', ' . $this->endRange . ').');
-               if (count($errors) > 0) return FALSE;
-               return TRUE;
+               if (!is_numeric($value)) {
+                       $errors->append('The given subject was not a valid number. Got: "' . $value . '"');
+                       return FALSE;
+               }
+
+               $startRange = (isset($validationOptions['startRange'])) ? intval($validationOptions['startRange']) : 0;
+               $endRange = (isset($validationOptions['endRange'])) ? intval($validationOptions['endRange']) : PHP_INT_MAX;
+               if ($startRange > $endRange) {
+                       $x = $startRange;
+                       $startRange = $endRange;
+                       $endRange = $x;
+               }
+               if ($value >= $startRange && $value <= $endRange) return TRUE;
+
+               $errors->append('The given subject was not in the valid range (' . $startRange . ', ' . $endRange . ').');
+               return FALSE;
        }
 }
 
index 90c647b..3677085 100644 (file)
@@ -31,23 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_RegularExpression implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * @var string The regular expression
-        */
-       protected $regularExpression;
-
-       /**
-        * Creates a RegularExpression validator with the given expression
+        * Returns TRUE, if the given property ($value) matches the given regular expression.
         *
-        * @param string The regular expression, must be ready to use with preg_match()
-        */
-       public function __construct($regularExpression) {
-               $this->regularExpression = $regularExpression;
-       }
-
-       /**
-        * Returns TRUE, if the given propterty ($proptertyValue) matches the given regular expression.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
@@ -55,10 +42,19 @@ class TX_EXTMVC_Validation_Validator_RegularExpression implements TX_EXTMVC_Vali
         * @return boolean TRUE if the value is valid, FALSE if an error occured
         */
        public function isValid($value, TX_EXTMVC_Validation_Errors &$errors, array $validationOptions = array()) {
-               if (!is_string($value) || preg_match($this->regularExpression, $value) === 0) {
+               if (!isset($validationOptions['regularExpression'])) {
+                       $errors->append('The regular expression was empty.');
+                       return FALSE;
+               }
+               $result = preg_match($validationOptions['regularExpression'], $value);
+               if ($result === 0) {
                        $errors->append('The given subject did not match the pattern.');
                        return FALSE;
                }
+               if ($result === FALSE) {
+                       $errors->append('The regular expression "' . $validationOptions['regularExpression'] . '" contained an error.');
+                       return FALSE;
+               }
                return TRUE;
        }
 }
index e7ff26f..a5557d7 100644 (file)
@@ -31,9 +31,10 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_
 class TX_EXTMVC_Validation_Validator_Text implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
-        * Returns TRUE, if the given propterty ($value) is a valid text (contains no XML tags).
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
+        * Returns TRUE, if the given property ($propertyValue) is a valid text (contains no XML tags).
+        *
+        * If at least one error occurred, the result is FALSE and any errors will
+        * be stored in the given errors object.
         *
         * @param mixed $value The value that should be validated
         * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_UUID.php b/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_UUID.php
deleted file mode 100644 (file)
index 27ff971..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-/*                                                                        *
- * This script belongs to the FLOW3 framework.                            *
- *                                                                        *
- * It is free software; you can redistribute it and/or modify it under    *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation, either version 3 of the License, or (at your *
- * option) any later version.                                             *
- *                                                                        *
- * This script is distributed in the hope that it will be useful, but     *
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
- * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
- * General Public License for more details.                               *
- *                                                                        *
- * You should have received a copy of the GNU Lesser General Public       *
- * License along with the script.                                         *
- * If not, see http://www.gnu.org/licenses/lgpl.html                      *
- *                                                                        *
- * The TYPO3 project - inspiring people to share!                         *
- *                                                                        */
-
-require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
-
-/**
- * Validator for Universally Unique Identifiers
- *
- * @version $ID:$
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- */
-class TX_EXTMVC_Validation_Validator_UUID implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
-
-       /**
-        * Returns TRUE, if the given property ($value) is a formally valid UUID.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
-        *
-        * @param mixed $value The value that should be validated
-        * @param TX_EXTMVC_Validation_Errors $errors An Errors object which will contain any errors which occurred during validation
-        * @param array $validationOptions Not used
-        * @return boolean TRUE if the value is valid, FALSE if an error occured
-        */
-       public function isValid($value, TX_EXTMVC_Validation_Errors &$errors, array $validationOptions = array()) {
-               if (!is_string($value) || !preg_match('/([a-f0-9]){8}-([a-f0-9]){4}-([a-f0-9]){4}-([a-f0-9]){4}-([a-f0-9]){12}/', $value)) {
-                       $errors->append('The given subject was not a valid UUID.');
-                       return FALSE;
-               }
-               return TRUE;
-       }
-}
-
-?>
\ No newline at end of file
index 98c7774..d119001 100644 (file)
@@ -20,6 +20,7 @@
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(PATH_tslib . 'class.tslib_content.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/View/Helper/TX_EXTMVC_View_Helper_AbstractHelper.php');
 
 /**
index b4dda7e..a466e9c 100644 (file)
@@ -30,9 +30,114 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/View/Helper/TX_EXTMVC_Vi
  */
 class TX_EXTMVC_View_Helper_TranslateHelper extends TX_EXTMVC_View_Helper_AbstractHelper {
 
+       /**
+        * @var string
+        */
+       protected $languagePath = 'Resources/Language/';
+
+       /**
+        * Local Language content
+        *
+        * @var string
+        **/
+       protected $LOCAL_LANG = array();
+
+       /**
+        * Local Language content charset for individual labels (overriding)
+        *
+        * @var string
+        **/
+       protected $LOCAL_LANG_charset = array();
+
+       /**
+        * Key of the language to use
+        *
+        * @var string
+        **/
+       protected $languageKey = 'default';
+
+       /**
+        * Pointer to alternative fall-back language to use
+        *
+        * @var string
+        **/
+       protected $LLkey = 'default';
+       var $altLLkey='';                       // .
+       var $LLtestPrefix='';                   // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
+       var $LLtestPrefixAlt='';                // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
+       
+
        public function render($view, $content, $arguments, $templateResource, $variables) {
+               $this->initializeLocalization();
                
        }
+       
+       /**
+        * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
+        * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
+        *
+        * @return      void
+        */
+       protected function initializeLocalization()     {
+                       $languageFilePath = t3lib_extMgm::extPath(strtolower($this->request->getControllerExtensionKey())) . $this->languagePath . 'locallang.php';
+
+                       if ($GLOBALS['TSFE']->config['config']['language'])     {
+                               $this->languageKey = $GLOBALS['TSFE']->config['config']['language'];
+                               if ($GLOBALS['TSFE']->config['config']['language_alt']) {
+                                       $this->alternativeLanguageKey = $GLOBALS['TSFE']->config['config']['language_alt'];
+                               }
+                       }
+
+                       // Read the strings in the required charset (since TYPO3 4.2)
+                       $this->LOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->languageKey, $GLOBALS['TSFE']->renderCharset);
+                       if ($this->alternativeLanguageKey)      {
+                               $tempLOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->alternativeLanguageKey);
+                               $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(), $tempLOCAL_LANG);
+                       }
+
+                       // TODO Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
+                       if (is_array($this->conf['_LOCAL_LANG.']))      {
+                               reset($this->conf['_LOCAL_LANG.']);
+                               while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
+                                       if (is_array($lA))      {
+                                               $k = substr($k,0,-1);
+                                               foreach($lA as $llK => $llV)    {
+                                                       if (!is_array($llV))    {
+                                                               $this->LOCAL_LANG[$k][$llK] = $llV;
+                                                                       // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages
+                                                               $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+       }
+       
+       /**
+        * Returns the localized label of the LOCAL_LANG key, $key
+        * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
+        *
+        * @param       string          The key from the LOCAL_LANG array for which to return the value.
+        * @param       string          Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
+        * @param       boolean         If true, the output label is passed through htmlspecialchars()
+        * @return      string          The value from LOCAL_LANG.
+        */
+       function translate($key, $default = '', $hsc=FALSE)     {
+               // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
+               if (isset($this->LOCAL_LANG[$this->languageKey][$key])) {
+                       $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->languageKey][$key], $this->LOCAL_LANG_charset[$this->languageKey][$key]);
+               } elseif ($this->alternativeLanguageKey && isset($this->LOCAL_LANG[$this->alternativeLanguageKey][$key]))       {
+                       $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->alternativeLanguageKey][$key], $this->LOCAL_LANG_charset[$this->alternativeLanguageKey][$key]);
+               } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
+                       $translation = $this->LOCAL_LANG['default'][$key];      // No charset conversion because default is english and thereby ASCII
+               } else {
+                       $translation = $default;
+               }
+
+               return $hsc ? htmlspecialchars($translation) : $translation;
+       }
+       
+       
 
 }
 
index 906aa82..5185113 100755 (executable)
@@ -45,58 +45,6 @@ abstract class TX_EXTMVC_View_AbstractView implements TX_EXTMVC_View_ViewInterfa
         */
        protected $contextVariables = array();
 
-       /**
-        * @var string
-        */
-       protected $languagePath = 'Resources/Language/';
-
-       /**
-        * Local Language content
-        *
-        * @var string
-        **/
-       protected $LOCAL_LANG = array();
-
-       /**
-        * Local Language content charset for individual labels (overriding)
-        *
-        * @var string
-        **/
-       protected $LOCAL_LANG_charset = array();
-
-       /**
-        * Key of the language to use
-        *
-        * @var string
-        **/
-       protected $languageKey = 'default';
-
-       /**
-        * Pointer to alternative fall-back language to use
-        *
-        * @var string
-        **/
-       protected $LLkey = 'default';
-       var $altLLkey='';                       // .
-       var $LLtestPrefix='';                   // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
-       var $LLtestPrefixAlt='';                // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
-
-       /**
-        * Constructs the view
-        */
-       public function __construct() {
-       }
-
-       /**
-        * Initializes the view after all dependencies have been injected
-        *
-        * @return void
-        */
-       public function initializeObject() {
-               $this->initializeView();
-               $this->initializeLocalization();
-       }
-
        /**
         * Sets the current request
         *
@@ -136,71 +84,6 @@ abstract class TX_EXTMVC_View_AbstractView implements TX_EXTMVC_View_ViewInterfa
        protected function initializeView() {
        }
        
-       /**
-        * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
-        * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
-        *
-        * @return      void
-        */
-       protected function initializeLocalization()     {
-                       $languageFilePath = t3lib_extMgm::extPath(strtolower($this->request->getControllerExtensionKey())) . $this->languagePath . 'locallang.php';
-
-                       if ($GLOBALS['TSFE']->config['config']['language'])     {
-                               $this->languageKey = $GLOBALS['TSFE']->config['config']['language'];
-                               if ($GLOBALS['TSFE']->config['config']['language_alt']) {
-                                       $this->alternativeLanguageKey = $GLOBALS['TSFE']->config['config']['language_alt'];
-                               }
-                       }
-
-                       // Read the strings in the required charset (since TYPO3 4.2)
-                       $this->LOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->languageKey, $GLOBALS['TSFE']->renderCharset);
-                       if ($this->alternativeLanguageKey)      {
-                               $tempLOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->alternativeLanguageKey);
-                               $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(), $tempLOCAL_LANG);
-                       }
-
-                       // TODO Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
-                       if (is_array($this->conf['_LOCAL_LANG.']))      {
-                               reset($this->conf['_LOCAL_LANG.']);
-                               while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
-                                       if (is_array($lA))      {
-                                               $k = substr($k,0,-1);
-                                               foreach($lA as $llK => $llV)    {
-                                                       if (!is_array($llV))    {
-                                                               $this->LOCAL_LANG[$k][$llK] = $llV;
-                                                                       // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages
-                                                               $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-       }
-       
-       /**
-        * Returns the localized label of the LOCAL_LANG key, $key
-        * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix
-        *
-        * @param       string          The key from the LOCAL_LANG array for which to return the value.
-        * @param       string          Alternative string to return IF no value is found set for the key, neither for the local language nor the default.
-        * @param       boolean         If true, the output label is passed through htmlspecialchars()
-        * @return      string          The value from LOCAL_LANG.
-        */
-       function translate($key, $default = '', $hsc=FALSE)     {
-               // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
-               if (isset($this->LOCAL_LANG[$this->languageKey][$key])) {
-                       $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->languageKey][$key], $this->LOCAL_LANG_charset[$this->languageKey][$key]);
-               } elseif ($this->alternativeLanguageKey && isset($this->LOCAL_LANG[$this->alternativeLanguageKey][$key]))       {
-                       $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->alternativeLanguageKey][$key], $this->LOCAL_LANG_charset[$this->alternativeLanguageKey][$key]);
-               } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
-                       $translation = $this->LOCAL_LANG['default'][$key];      // No charset conversion because default is english and thereby ASCII
-               } else {
-                       $translation = $default;
-               }
-
-               return $hsc ? htmlspecialchars($translation) : $translation;
-       }
-       
 }
 
 ?>
index 0dc1465..57daa3d 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
-/**
- *
- * @version $Id:$
- */
-
 /**
  * An empty view - a special case.
  *
index 422b513..03df05a 100644 (file)
@@ -21,6 +21,7 @@ declare(ENCODING = 'utf-8');
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(PATH_tslib . 'class.tslib_content.php');
 require_once(PATH_t3lib . 'class.t3lib_parsehtml.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Utility/TX_EXTMVC_Utility_Strings.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/View/Helper/TX_EXTMVC_View_Helper_ForHelper.php');
index b126768..2569a96 100644 (file)
@@ -63,6 +63,11 @@ class TX_EXTMVC_Dispatcher {
         */
        protected $postParameters;
 
+       /**
+        * @var array An array of registered classes (class files with path)
+        */
+       protected $registeredClassNames;
+
        /**
         * Constructs this dispatcher
         *
@@ -80,7 +85,7 @@ class TX_EXTMVC_Dispatcher {
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
-               // TODO Add an AJAX dispatcher
+               // $time_start = microtime(true);               
                $parameters = t3lib_div::_GET('tx_extmvc');
                // TODO Is stripslashes secure enough?
                $extensionKey = isset($parameters['extension']) ? stripslashes($parameters['extension']) : $configuration['extension'];
@@ -88,11 +93,20 @@ class TX_EXTMVC_Dispatcher {
                $action = isset($parameters['action']) ? stripslashes($parameters['action']) : $configuration['action'];
                
                $request = t3lib_div::makeInstance('TX_EXTMVC_Web_Request');
-               $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
-               $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
                $request->setControllerExtensionKey($extensionKey);
                $request->setControllerName($controller);
                $request->setControllerActionName($action);
+
+               $controllerObjectName = $request->getControllerObjectName();
+               $controller = t3lib_div::makeInstance($controllerObjectName);
+               
+               if (!$controller instanceof TX_EXTMVC_Controller_AbstractController) throw new TX_EXTMVC_Exception_InvalidController('Invalid controller "' . $controllerObjectName . '". The controller must be a valid request handling controller.', 1202921619);
+
+               if (!$controller->isCachableAction($action) && $this->cObj->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {                      
+                       $this->cObj->convertToUserIntObject();
+                       return $content;
+               }
+
                $arguments = t3lib_div::makeInstance('TX_EXTMVC_Controller_Arguments');
                foreach (t3lib_div::GParrayMerged('tx_' . strtolower($extensionKey)) as $key => $value) {
                        $argument = new TX_EXTMVC_Controller_Argument($key, 'Raw');
@@ -100,13 +114,10 @@ class TX_EXTMVC_Dispatcher {
                        $arguments->addArgument($argument);
                }
                $request->setArguments($arguments);
+               $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
+               $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
                $response = t3lib_div::makeInstance('TX_EXTMVC_Web_Response');
 
-               $controllerObjectName = $request->getControllerObjectName();
-               $controller = t3lib_div::makeInstance($controllerObjectName);
-               
-               if (!$controller instanceof TX_EXTMVC_Controller_AbstractController) throw new TX_EXTMVC_Exception_InvalidController('Invalid controller "' . $controllerObjectName . '". The controller must be a valid request handling controller.', 1202921619);
-
                $settings = is_array($configuration['settings.']) ? $configuration['settings.'] : array();
                $controller->injectSettings($settings);
 
@@ -114,15 +125,15 @@ class TX_EXTMVC_Dispatcher {
                try {
                        $controller->processRequest($request, $response);                       
                } catch (TX_EXTMVC_Exception_StopAction $ignoredException) {                    
-               } catch (TX_EXTMVC_Exception_StopUncachedAction $ignoredException) {
-                       $this->cObj->convertToUserIntObject();
                }
-               
                $session->commit();
                $session->clear();
                
                $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionKey()] = implode("\n", $response->getAdditionalHeaderTags());
                
+               // $time_end = microtime(true);
+               // debug($time_end - $time_start,-1);
+               
                return $response->getContent();
        }
 
@@ -134,16 +145,21 @@ class TX_EXTMVC_Dispatcher {
         * @return void
         */
        protected function autoLoadClasses($className) {
-               $classNameParts = explode('_', $className);
-               if ($classNameParts[0] === 'ux') {
-                       array_shift($classNameParts);
-               }
-               if (count($classNameParts) > 2 && $classNameParts[0] === 'TX') {
-                       $classFilePathAndName = t3lib_extMgm::extPath(strtolower($classNameParts[1])) . 'Classes/';
-                       $classFilePathAndName .= implode(array_slice($classNameParts, 2, -1), '/') . '/';
-                       $classFilePathAndName .= implode('_', $classNameParts) . '.php';
+               if (empty($this->registeredClassNames[$className])) {
+                       $classNameParts = explode('_', $className);
+                       if ($classNameParts[0] === 'ux') {
+                               array_shift($classNameParts);
+                       }
+                       if (count($classNameParts) > 2 && $classNameParts[0] === 'TX') {
+                               $classFilePathAndName = t3lib_extMgm::extPath(strtolower($classNameParts[1])) . 'Classes/';
+                               $classFilePathAndName .= implode(array_slice($classNameParts, 2, -1), '/') . '/';
+                               $classFilePathAndName .= implode('_', $classNameParts) . '.php';
+                       }
+                       if (isset($classFilePathAndName) && file_exists($classFilePathAndName)) {
+                               require_once($classFilePathAndName);
+                               $this->registeredClassNames[$className] = $classFilePathAndName;
+                       }
                }
-               if (isset($classFilePathAndName) && file_exists($classFilePathAndName)) require_once($classFilePathAndName);                    
        }
 
 }