EXTMVC:
authorJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 09:01:44 +0000 (09:01 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 09:01:44 +0000 (09:01 +0000)
* first step of refactored validation

16 files changed:
typo3/sysext/extbase/Classes/DomainObject/TX_EXTMVC_DomainObject_AbstractDomainObject.php
typo3/sysext/extbase/Classes/Validation/TX_EXTMVC_Validation_ValidatorInterface.php [deleted file]
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_AbstractValidator.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_Alphanumeric.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ChainValidator.php [new file with mode: 0644]
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_Raw.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
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php [new file with mode: 0644]

index 3058676..dc9b5f5 100644 (file)
@@ -48,7 +48,7 @@ abstract class TX_EXTMVC_DomainObject_AbstractDomainObject {
        }
                
        /**
-        * This is the magic wakeup() method. It's invoked by the unserialize statement in the reconstitution process
+        * This is the magic __wakeup() method. It's invoked by the unserialize statement in the reconstitution process
         * of the object. If you want to implement your own __wakeup() method in your Domain Object you have to call 
         * parent::__wakeup() first!
         *
@@ -90,7 +90,7 @@ abstract class TX_EXTMVC_DomainObject_AbstractDomainObject {
                if (property_exists($this, $propertyName)) {
                        $this->$propertyName = $value;
                } else {
-                       // throw new TX_EXTMVC_Persistence_Exception_UnknownProperty('The property "' . $propertyName . '" doesn\'t exist in this object.', 1233270476);
+                       // TODO throw new TX_EXTMVC_Persistence_Exception_UnknownProperty('The property "' . $propertyName . '" doesn\'t exist in this object.', 1233270476);
                }
        }
        
diff --git a/typo3/sysext/extbase/Classes/Validation/TX_EXTMVC_Validation_ValidatorInterface.php b/typo3/sysext/extbase/Classes/Validation/TX_EXTMVC_Validation_ValidatorInterface.php
deleted file mode 100644 (file)
index 8fa2889..0000000
+++ /dev/null
@@ -1,42 +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!                         *
- *                                                                        */
-
-/**
- * Contract for a validator
- *
- * @version $ID:$
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- */
-interface TX_EXTMVC_Validation_ValidatorInterface {
-
-       /**
-        * Returns TRUE, if the given propterty ($proptertyValue) is a valid.
-        * Any errors will be stored in the given errors object.
-        * If at least one error occurred, the result is FALSE.
-        *
-        * @param  object $propertyValue: The value that should be validated
-        * @return boolean TRUE if the value could be validated. FALSE if an error occured
-        */
-       public function isValidProperty($propertyValue, TX_EXTMVC_Validation_Errors &$errors);
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_AbstractValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_AbstractValidator.php
new file mode 100644 (file)
index 0000000..ac561de
--- /dev/null
@@ -0,0 +1,35 @@
+<?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');
+
+/**
+ * Abstract validator
+ *
+ * @version $Id: $
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+abstract class TX_EXTMVC_Validation_Validator_AbstractValidator implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
+
+}
+
+?>
\ No newline at end of file
index d22875e..0401e34 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for alphanumeric strings
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_Alphanumeric {
+class TX_EXTMVC_Validation_Validator_Alphanumeric implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given property ($propertyValue) is a valid
diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ChainValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ChainValidator.php
new file mode 100644 (file)
index 0000000..efcfa31
--- /dev/null
@@ -0,0 +1,96 @@
+<?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 to chain many validators
+ *
+ * @version $ID:$
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ * @scope prototype
+ */
+class TX_EXTMVC_Validation_Validator_ChainValidator implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
+
+       /**
+        * @var array
+        */
+       protected $validators = array();
+
+       /**
+        * Checks if the given value is valid according to the validators of the chain..
+        *
+        * 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
+        * @param array $validationOptions Not used
+        * @return boolean TRUE if the value is valid, FALSE if an error occured
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
+        */
+       public function isValid($value, TX_EXTMVC_Validation_Errors &$errors, array $validationOptions = array()) {
+               $subjectIsValid = TRUE;
+               foreach ($this->validators as $validator) {
+                       $subjectIsValid &= $validator->isValid($value, $errors);
+               }
+               return (boolean)$subjectIsValid;
+       }
+
+       /**
+        * Adds a new validator to the chain. Returns the index of the chain entry.
+        *
+        * @param TX_EXTMVC_Validation_Validator_ValidatorInterface $validator The validator that should be added
+        * @return integer The index of the new chain entry
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
+        */
+       public function addValidator(TX_EXTMVC_Validation_Validator_ValidatorInterface $validator) {
+               $this->validators[] = $validator;
+               return count($this->validators) - 1;
+       }
+
+       /**
+        * Returns the validator with the given index of the chain.
+        *
+        * @param integer $index The index of the validator that should be returned
+        * @return TX_EXTMVC_Validation_Validator_ValidatorInterface The requested validator
+        * @throws TX_EXTMVC_Validation_Exception_InvalidChainIndex
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
+        */
+       public function getValidator($index) {
+               if (!isset($this->validators[$index])) throw new TX_EXTMVC_Validation_Exception_InvalidChainIndex('Invalid chain index.', 1207215864);
+               return $this->validators[$index];
+       }
+
+       /**
+        * Removes the validator with the given index of the chain.
+        *
+        * @param integer $index The index of the validator that should be removed
+        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
+        */
+       public function removeValidator($index) {
+               if (!isset($this->validators[$index])) throw new TX_EXTMVC_Validation_Exception_InvalidChainIndex('Invalid chain index.', 1207020177);
+               unset($this->validators[$index]);
+       }
+}
+
+?>
\ No newline at end of file
index b5360f3..040ff7c 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for email addresses
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_EmailAddress {
+class TX_EXTMVC_Validation_Validator_EmailAddress implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given property ($proptertyValue) is a valid email address.
index 5212142..9e21bbe 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for floats
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_Float {
+class TX_EXTMVC_Validation_Validator_Float implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given propterty ($proptertyValue) is a valid float.
index 71c49b1..f9f2bfc 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for integers
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_Integer {
+class TX_EXTMVC_Validation_Validator_Integer implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given propterty ($proptertyValue) is a valid integer.
index 22f369d..c8034c5 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for not empty values
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_NotEmpty {
+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).
index bcb8ab0..391ec2d 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for general numbers
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_Number {
+class TX_EXTMVC_Validation_Validator_Number implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given propterty ($proptertyValue) is a valid number.
index a3b4784..4f2fd2f 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for general numbers
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_NumberRange {
+class TX_EXTMVC_Validation_Validator_NumberRange implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * The start value of the range
index 4eedf9d..ff205d0 100644 (file)
@@ -20,6 +20,8 @@
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * A validator which accepts any input
  *
index 7ddd21c..f100f63 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for regular expressions
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_RegularExpression {
+class TX_EXTMVC_Validation_Validator_RegularExpression implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * @var string The regular expression
index 7d49492..a4218b0 100644 (file)
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php');
+
 /**
  * Validator for text
  *
  * @version $ID:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class TX_EXTMVC_Validation_Validator_Text {
+class TX_EXTMVC_Validation_Validator_Text implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given propterty ($propertyValue) is a valid text (contains no XML tags).
index b66d2a6..be41a15 100644 (file)
  * 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 {
+class TX_EXTMVC_Validation_Validator_UUID implements TX_EXTMVC_Validation_Validator_ValidatorInterface {
 
        /**
         * Returns TRUE, if the given property ($propertyValue) is a formally valid UUID.
diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php b/typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ValidatorInterface.php
new file mode 100644 (file)
index 0000000..0aa4a06
--- /dev/null
@@ -0,0 +1,42 @@
+<?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!                         *
+ *                                                                        */
+
+/**
+ * Contract for a validator
+ *
+ * @version $ID:$
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ */
+interface TX_EXTMVC_Validation_Validator_ValidatorInterface {
+
+       /**
+        * Returns TRUE, if the given propterty ($proptertyValue) is a valid.
+        * Any errors will be stored in the given errors object.
+        * If at least one error occurred, the result is FALSE.
+        *
+        * @param  object $propertyValue: The value that should be validated
+        * @return boolean TRUE if the value could be validated. FALSE if an error occured
+        */
+       public function isValidProperty($propertyValue, TX_EXTMVC_Validation_Errors &$errors);
+}
+
+?>
\ No newline at end of file