[TASK] Make preperations for backporting Flow validation api 90/21190/5
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sun, 2 Jun 2013 11:36:59 +0000 (13:36 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 4 Jun 2013 19:46:07 +0000 (21:46 +0200)
Synced some parts of Extbase validation with the one of
Flow without changing actual behaviour.

Releases: 6.2
Resolves: #48767
Change-Id: I0801f4faaa2d9e0fea31e51704ff0a30ca2c4ccb
Reviewed-on: https://review.typo3.org/21190
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
26 files changed:
typo3/sysext/extbase/Classes/Error/Result.php
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Classes/Validation/Error.php
typo3/sysext/extbase/Classes/Validation/Exception.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php
typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php
typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php
typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php
typo3/sysext/extbase/Tests/Unit/Error/ResultTest.php
typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php

index b03a735..02cfdb5 100644 (file)
@@ -34,16 +34,34 @@ class Result {
        protected $errors = array();
 
        /**
+        * Caches the existence of errors
+        * @var boolean
+        */
+       protected $errorsExist = FALSE;
+
+       /**
         * @var array<\TYPO3\CMS\Extbase\Error\Warning>
         */
        protected $warnings = array();
 
        /**
+        * Caches the existence of warning
+        * @var boolean
+        */
+       protected $warningsExist = FALSE;
+
+       /**
         * @var array<\TYPO3\CMS\Extbase\Error\Notice>
         */
        protected $notices = array();
 
        /**
+        * Caches the existence of notices
+        * @var boolean
+        */
+       protected $noticesExist = FALSE;
+
+       /**
         * The result objects for the sub properties
         *
         * @var array<\TYPO3\CMS\Extbase\Error\Result>
@@ -51,6 +69,33 @@ class Result {
        protected $propertyResults = array();
 
        /**
+        * @var \TYPO3\CMS\Extbase\Error\Result
+        */
+       protected $parent = NULL;
+
+       /**
+        * Injects the parent result and propagates the
+        * cached error states upwards
+        *
+        * @param \TYPO3\CMS\Extbase\Error\Error $parent
+        * @return void
+        */
+       public function setParent(Result $parent) {
+               if ($this->parent !== $parent) {
+                       $this->parent = $parent;
+                       if ($this->hasErrors()) {
+                               $parent->setErrorsExist();
+                       }
+                       if ($this->hasWarnings()) {
+                               $parent->setWarningsExist();
+                       }
+                       if ($this->hasNotices()) {
+                               $parent->setNoticesExist();
+                       }
+               }
+       }
+
+       /**
         * Add an error to the current Result object
         *
         * @param \TYPO3\CMS\Extbase\Error\Error $error
@@ -59,6 +104,7 @@ class Result {
         */
        public function addError(\TYPO3\CMS\Extbase\Error\Error $error) {
                $this->errors[] = $error;
+               $this->setErrorsExist();
        }
 
        /**
@@ -70,6 +116,7 @@ class Result {
         */
        public function addWarning(\TYPO3\CMS\Extbase\Error\Warning $warning) {
                $this->warnings[] = $warning;
+               $this->setWarningsExist();
        }
 
        /**
@@ -81,6 +128,7 @@ class Result {
         */
        public function addNotice(\TYPO3\CMS\Extbase\Error\Notice $notice) {
                $this->notices[] = $notice;
+               $this->setNoticesExist();
        }
 
        /**
@@ -174,14 +222,82 @@ class Result {
                if (count($pathSegments) === 0) {
                        return $this;
                }
+
                $propertyName = array_shift($pathSegments);
+
                if (!isset($this->propertyResults[$propertyName])) {
-                       $this->propertyResults[$propertyName] = new \TYPO3\CMS\Extbase\Error\Result();
+                       $this->propertyResults[$propertyName] = new Result();
                }
+
                return $this->propertyResults[$propertyName]->recurseThroughResult($pathSegments);
        }
 
        /**
+        * Sets the error cache to TRUE and propagates the information
+        * upwards the Result-Object Tree
+        *
+        * @return void
+        */
+       protected function setErrorsExist() {
+               $this->errorsExist = TRUE;
+               if ($this->parent !== NULL) {
+                       $this->parent->setErrorsExist();
+               }
+       }
+
+       /**
+        * Sets the warning cache to TRUE and propagates the information
+        * upwards the Result-Object Tree
+        *
+        * @return void
+        */
+       protected function setWarningsExist() {
+               $this->warningsExist = TRUE;
+               if ($this->parent !== NULL) {
+                       $this->parent->setWarningsExist();
+               }
+       }
+
+       /**
+        * Sets the notices cache to TRUE and propagates the information
+        * upwards the Result-Object Tree
+        *
+        * @return void
+        */
+       protected function setNoticesExist() {
+               $this->noticesExist = TRUE;
+               if ($this->parent !== NULL) {
+                       $this->parent->setNoticesExist();
+               }
+       }
+
+       /**
+        * Does the current Result object have Notices, Errors or Warnings? (Recursively)
+        *
+        * @return boolean
+        */
+       public function hasMessages() {
+               return $this->errorsExist || $this->noticesExist || $this->warningsExist;
+       }
+
+       /**
+        * Clears the result
+        *
+        * @return void
+        */
+       public function clear() {
+               $this->errors = array();
+               $this->notices = array();
+               $this->warnings = array();
+
+               $this->warningsExist = FALSE;
+               $this->noticesExist = FALSE;
+               $this->errorsExist = FALSE;
+
+               $this->propertyResults = array();
+       }
+
+       /**
         * Internal use only!
         *
         * @param string $propertyName
@@ -232,7 +348,7 @@ class Result {
 
        /**
         * Get a list of all Error objects recursively. The result is an array,
-        * where the key is the property path where the error occured, and the
+        * where the key is the property path where the error occurred, and the
         * value is a list of all errors (stored as array)
         *
         * @return array<\TYPO3\CMS\Extbase\Error\Error>
@@ -260,7 +376,7 @@ class Result {
 
        /**
         * Get a list of all Notice objects recursively. The result is an array,
-        * where the key is the property path where the notice occured, and the
+        * where the key is the property path where the notice occurred, and the
         * value is a list of all notices (stored as array)
         *
         * @return array<\TYPO3\CMS\Extbase\Error\Notice>
@@ -278,13 +394,13 @@ class Result {
         * Flatten a tree of Result objects, based on a certain property.
         *
         * @param string $propertyName
-        * @param array &$result
+        * @param array $result
         * @param array $level
         * @return void
         */
        public function flattenTree($propertyName, &$result, $level) {
-               if (count($this->{$propertyName}) > 0) {
-                       $result[implode('.', $level)] = $this->{$propertyName};
+               if (count($this->$propertyName) > 0) {
+                       $result[implode('.', $level)] = $this->$propertyName;
                }
                foreach ($this->propertyResults as $subPropertyName => $subResult) {
                        array_push($level, $subPropertyName);
@@ -317,9 +433,9 @@ class Result {
         * @param string $adderName
         * @return void
         */
-       protected function mergeProperty(\TYPO3\CMS\Extbase\Error\Result $otherResult, $getterName, $adderName) {
-               foreach ($otherResult->{$getterName}() as $messageInOtherResult) {
-                       $this->{$adderName}($messageInOtherResult);
+       protected function mergeProperty(Result $otherResult, $getterName, $adderName) {
+               foreach ($otherResult->$getterName() as $messageInOtherResult) {
+                       $this->$adderName($messageInOtherResult);
                }
        }
 
index e7da4e5..5c659a3 100644 (file)
@@ -549,6 +549,28 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        }
                }
        }
+
+       /**
+        * Returns a map of action method names and their parameters.
+        *
+        * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+        * @return array Array of method parameters by action name
+        */
+       static public function getActionMethodParameters($objectManager) {
+               $reflectionService = $objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService');
+
+               $result = array();
+
+               $className = get_called_class();
+               $methodNames = get_class_methods($className);
+               foreach ($methodNames as $methodName) {
+                       if (strlen($methodName) > 6 && strpos($methodName, 'Action', strlen($methodName) - 6) !== FALSE) {
+                               $result[$methodName] = $reflectionService->getMethodParameters($className, $methodName);
+                       }
+               }
+
+               return $result;
+       }
 }
 
-?>
\ No newline at end of file
+?>
index c2fddd1..7a3c601 100644 (file)
@@ -27,19 +27,20 @@ namespace TYPO3\CMS\Extbase\Validation;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Objects of this kind contain a list of validation errors which occurred during
- * validation.
+ * This object holds a validation error.
+ *
  */
 class Error extends \TYPO3\CMS\Extbase\Error\Error {
 
        /**
-        * @var string The default (english) error message.
+        * @var string
         */
        protected $message = 'Unknown validation error';
 
        /**
-        * @var string The error code
+        * @var string
         */
        protected $code = 1201447005;
 }
index 83b755f..0518d71 100644 (file)
@@ -27,8 +27,11 @@ namespace TYPO3\CMS\Extbase\Validation;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * A generic validation exception
+ *
+ * @api
  */
 class Exception extends \TYPO3\CMS\Extbase\Exception {
 
index fc98578..c7879a3 100644 (file)
@@ -35,6 +35,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
 abstract class AbstractCompositeValidator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface, \Countable {
 
        /**
+        * This contains the supported options, their default values and descriptions.
+        *
+        * @var array
+        */
+       protected $supportedOptions = array();
+
+       /**
         * @var array
         */
        protected $options = array();
@@ -45,12 +52,19 @@ abstract class AbstractCompositeValidator implements \TYPO3\CMS\Extbase\Validati
        protected $validators;
 
        /**
+        * @var \SplObjectStorage
+        */
+       protected $validatedInstancesContainer;
+
+       /**
         * @var array
         */
        protected $errors = array();
 
        /**
-        * Constructs the validator conjunction
+        * Constructs the composite validator and sets validation options
+        *
+        * @api
         */
        public function __construct() {
                $this->validators = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
@@ -81,6 +95,7 @@ abstract class AbstractCompositeValidator implements \TYPO3\CMS\Extbase\Validati
         *
         * @param \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $validator The validator that should be added
         * @return void
+        * @api
         */
        public function addValidator(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $validator) {
                $this->validators->attach($validator);
@@ -104,10 +119,40 @@ abstract class AbstractCompositeValidator implements \TYPO3\CMS\Extbase\Validati
         * Returns the number of validators contained in this conjunction.
         *
         * @return integer The number of validators
+        * @api
         */
        public function count() {
                return count($this->validators);
        }
+
+       /**
+        * Returns the child validators of this Composite Validator
+        *
+        * @return \SplObjectStorage
+        */
+       public function getValidators() {
+               return $this->validators;
+       }
+
+       /**
+        * Returns the options for this validator
+        *
+        * @return array
+        */
+       public function getOptions() {
+               return $this->options;
+       }
+
+       /**
+        * Allows to set a container to keep track of validated instances.
+        *
+        * @param \SplObjectStorage $validatedInstancesContainer A container to keep track of validated instances
+        * @return void
+        * @api
+        */
+       public function setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer) {
+               $this->validatedInstancesContainer = $validatedInstancesContainer;
+       }
 }
 
 ?>
\ No newline at end of file
index b2992f8..93ac1d8 100644 (file)
@@ -33,6 +33,24 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
 abstract class AbstractValidator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {
 
        /**
+        * Specifies whether this validator accepts empty values.
+        *
+        * If this is TRUE, the validators isValid() method is not called in case of an empty value
+        * Note: A value is considered empty if it is NULL or an empty string!
+        * By default all validators except for NotEmpty and the Composite Validators accept empty values
+        *
+        * @var boolean
+        */
+       protected $acceptsEmptyValues = TRUE;
+
+       /**
+        * This contains the supported options, their default values, types and descriptions.
+        *
+        * @var array
+        */
+       protected $supportedOptions = array();
+
+       /**
         * @var array
         */
        protected $options = array();
@@ -119,6 +137,23 @@ abstract class AbstractValidator implements \TYPO3\CMS\Extbase\Validation\Valida
                // the following is @deprecated since Extbase 1.4.0:
                $this->errors[] = new \TYPO3\CMS\Extbase\Validation\Error($message, $code, $arguments, $title);
        }
+
+       /**
+        * Returns the options of this validator
+        *
+        * @return array
+        */
+       public function getOptions() {
+               return $this->options;
+       }
+
+       /**
+        * @param mixed $value
+        * @return boolean TRUE if the given $value is NULL or an empty string ('')
+        */
+       final protected function isEmpty($value) {
+               return $value === NULL || $value === '';
+       }
 }
 
 ?>
\ No newline at end of file
index 1635840..7cb6d8e 100644 (file)
@@ -29,8 +29,10 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  ***************************************************************/
 /**
  * Validator for alphanumeric strings
+ *
+ * @api
  */
-class AlphanumericValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class AlphanumericValidator extends AbstractValidator {
 
        /**
         * Returns TRUE, if the given property ($propertyValue) is a valid
index 6f8e531..226381c 100644 (file)
@@ -27,13 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator to chain many validators in a conjunction (logical and). So every
- * validator has to be valid, to make the whole conjunction valid.
+ * Validator to chain many validators in a conjunction (logical and).
  *
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ * @api
  */
-class ConjunctionValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator {
+class ConjunctionValidator extends AbstractCompositeValidator {
 
        /**
         * Checks if the given value is valid according to the validators of the conjunction.
index 252bdf6..a003b36 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for DateTime objects
+ * Validator for DateTime objects.
+ *
+ * @api
  */
-class DateTimeValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class DateTimeValidator extends AbstractValidator {
 
        /**
         * Checks if the given value is a valid DateTime object.
index 7cb2327..24e6699 100644 (file)
@@ -27,14 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator to chain many validators in a disjunction (logical or). So only one
- * validator has to be valid, to make the whole disjunction valid. Errors are
- * only returned if all validators failed.
+ * Validator to chain many validators in a disjunction (logical or).
  *
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
+ * @api
  */
-class DisjunctionValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator {
+class DisjunctionValidator extends AbstractCompositeValidator {
 
        /**
         * Checks if the given value is valid according to the validators of the
index 2a66d5e..d8cd99b 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * Validator for email addresses
+ *
+ * @api
  */
-class EmailAddressValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class EmailAddressValidator extends AbstractValidator {
 
        /**
         * Checks if the given value is a valid email address.
index 7c15b33..a61d7bf 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for floats
+ * Validator for floats.
+ *
+ * @api
  */
-class FloatValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class FloatValidator extends AbstractValidator {
 
        /**
         * Checks if the given value is a valid float.
index 69eb98c..7b7120a 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for integers
+ * Validator for integers.
+ *
+ * @api
  */
-class IntegerValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class IntegerValidator extends AbstractValidator {
 
        /**
         * Checks if the given value is a valid integer.
index 4759a28..97ad023 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for not empty values
+ * Validator for not empty values.
+ *
+ * @api
  */
-class NotEmptyValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class NotEmptyValidator extends AbstractValidator {
 
        /**
         * Checks if the given property ($propertyValue) is not empty (NULL, empty string, empty array or empty object).
index 83b0691..06f39be 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
  * Validator for general numbers
+ *
+ * @api
  */
-class NumberRangeValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class NumberRangeValidator extends AbstractValidator {
 
        /**
         * Returns TRUE, if the given property ($propertyValue) is a valid number in the given range.
index 309c2bd..44bda86 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for general numbers
+ * Validator for general numbers.
+ *
+ * @api
  */
-class NumberValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class NumberValidator extends AbstractValidator {
 
        /**
         * Checks if the given value is a valid number.
index c94f996..fe4ca7b 100644 (file)
@@ -28,17 +28,19 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Contract for an object validator
+ * Contract for a validator
  *
- * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
+ * @api
  */
-interface ObjectValidatorInterface extends \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {
+interface ObjectValidatorInterface extends ValidatorInterface {
 
        /**
         * Checks the given object can be validated by the validator implementation
         *
         * @param object $object The object to be checked
         * @return boolean TRUE if this validator can validate instances of the given object or FALSE if it can't
+        *
+        * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
         */
        public function canValidate($object);
 
@@ -50,6 +52,8 @@ interface ObjectValidatorInterface extends \TYPO3\CMS\Extbase\Validation\Validat
         * @param object $object The object containing the property to validate
         * @param string $propertyName Name of the property to validate
         * @return boolean TRUE if the property value is valid, FALSE if an error occured
+        *
+        * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
         */
        public function isPropertyValid($object, $propertyName);
 }
index f794c4f..3304c37 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * A validator which accepts any input
+ * A validator which accepts any input.
+ *
+ * @api
  */
-class RawValidator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {
+class RawValidator implements ValidatorInterface {
 
        /**
         * Always returns TRUE
index 03b0334..110b76e 100644 (file)
@@ -27,12 +27,14 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator based on regular expressions
+ * Validator based on regular expressions.
  *
- * The regular expression is specified in the options by using the array key "regularExpression"
+ * @api
  */
-class RegularExpressionValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class RegularExpressionValidator extends AbstractValidator {
+
 
        /**
         * Returns TRUE, if the given property ($value) matches the given regular expression.
index f28cda6..184ac38 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for string length
+ * Validator for string length.
+ *
+ * @api
  */
-class StringLengthValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class StringLengthValidator extends AbstractValidator {
 
        /**
         * Returns TRUE, if the given property ($value) is a valid string and its length
index 43a46b8..ae9b70a 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for string length
+ * Validator for strings.
+ *
+ * @api
  */
-class StringValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class StringValidator extends AbstractValidator {
 
        /**
         * Returns TRUE, if the given property ($value) is a valid string.
index 39554de..20e9de5 100644 (file)
@@ -27,10 +27,13 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Validator for text
+ * Validator for "plain" text.
+ *
+ * @api
  */
-class TextValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
+class TextValidator extends AbstractValidator {
 
        /**
         * Returns TRUE, if the given property ($propertyValue) is a valid text (contains no XML tags).
index 07244b8..ceec3b6 100644 (file)
@@ -28,18 +28,7 @@ namespace TYPO3\CMS\Extbase\Validation\Validator;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Contract for a validator. This interface has drastically changed with Extbase 1.4.0, so that's why this interface does not contain any mandatory methods.
- *
- * For compatibility with Extbase < 1.4.0, the following methods need to exist:
- * - setOptions($options) to set validation options
- * - isValid($object) to check whether an object is valid (returns boolean value)
- * - getErrors() to get errors occuring during validation.
- *
- * For Extbase >= 1.4.0, the following methods need to exist:
- * - __construct($options) to set validation options
- * - validate($object) to check whether the given object is valid. Returns a \TYPO3\CMS\Extbase\Error\Result object which can then be checked for validity.
- *
- * Please see the source file for proper documentation of the above methods.
+ * Contract for a validator
  *
  * @api
  */
index cf03add..f350c44 100644 (file)
@@ -39,35 +39,35 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface {
 
        /**
         * Match validator names and options
+        * @todo: adjust [a-z0-9_:.\\\\] once Tx_Extbase_Foo syntax is outdated.
         *
         * @var string
         */
        const PATTERN_MATCH_VALIDATORS = '/
-                       (?:^|,\\s*)
+                       (?:^|,\s*)
                        (?P<validatorName>[a-z0-9_:.\\\\]+)
-                       \\s*
-                       (?:\\(
-                               (?P<validatorOptions>(?:\\s*[a-z0-9]+\\s*=\\s*(?:
+                       \s*
+                       (?:\(
+                               (?P<validatorOptions>(?:\s*[a-z0-9]+\s*=\s*(?:
                                        "(?:\\\\"|[^"])*"
                                        |\'(?:\\\\\'|[^\'])*\'
-                                       |(?:\\s|[^,"\']*)
-                               )(?:\\s|,)*)*)
-                       \\))?
+                                       |(?:\s|[^,"\']*)
+                               )(?:\s|,)*)*)
+                       \))?
                /ixS';
 
        /**
         * Match validator options (to parse actual options)
-        *
         * @var string
         */
        const PATTERN_MATCH_VALIDATOROPTIONS = '/
-                       \\s*
+                       \s*
                        (?P<optionName>[a-z0-9]+)
-                       \\s*=\\s*
+                       \s*=\s*
                        (?P<optionValue>
                                "(?:\\\\"|[^"])*"
                                |\'(?:\\\\\'|[^\'])*\'
-                               |(?:\\s|[^,"\']*)
+                               |(?:\s|[^,"\']*)
                        )
                /ixS';
 
@@ -354,7 +354,7 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface {
                                /**
                                 * Shorthand built in
                                 */
-                               $possibleClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\' . $this->unifyDataType($validatorName);
+                               $possibleClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\' . $this->getValidatorType($validatorName);
                        }
                } else {
                        /**
@@ -383,12 +383,12 @@ class ValidatorResolver implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * Preprocess data types. Used to map primitive PHP types to DataTypes used in Extbase.
+        * Used to map PHP types to validator types.
         *
         * @param string $type Data type to unify
         * @return string unified data type
         */
-       protected function unifyDataType($type) {
+       protected function getValidatorType($type) {
                switch ($type) {
                        case 'int':
                                $type = 'Integer';
index 7170886..c899961 100644 (file)
@@ -152,7 +152,7 @@ class ResultTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @param string $dataTypeInSingular
         * @param string $dataTypeInPlural
         */
-       public function hasMessageshouldReturnTrueIfSubObjectHasErrors($dataTypeInSingular, $dataTypeInPlural) {
+       public function hasMessagesShouldReturnTrueIfSubObjectHasErrors($dataTypeInSingular, $dataTypeInPlural) {
                $addMethodName = 'add' . $dataTypeInSingular;
                $methodName = 'has' . $dataTypeInPlural;
                $message = $this->getMockMessage($dataTypeInSingular);
index f82c224..f06c1e7 100644 (file)
@@ -377,11 +377,11 @@ class ValidatorResolverTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function resolveValidatorObjectNameCallsUnifyDataType() {
+       public function resolveValidatorObjectNameCallsGetValidatorType() {
                $validatorName = uniqid('FooValidator');
                eval('namespace TYPO3\CMS\Extbase\Validation\Validator;' . LF . 'class ' . $validatorName . 'Validator implements \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface {}');
-               $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('unifyDataType'));
-               $mockValidatorResolver->expects($this->once())->method('unifyDataType')->with($validatorName)->will($this->returnValue($validatorName));
+               $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('getValidatorType'));
+               $mockValidatorResolver->expects($this->once())->method('getValidatorType')->with($validatorName)->will($this->returnValue($validatorName));
 
                $mockValidatorResolver->_call('resolveValidatorObjectName', $validatorName);
        }
@@ -390,26 +390,26 @@ class ValidatorResolverTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function unifyDataTypeCorrectlyRenamesPhpDataTypes() {
-               $this->assertEquals('Integer', $this->validatorResolver->_call('unifyDataType', 'integer'));
-               $this->assertEquals('Integer', $this->validatorResolver->_call('unifyDataType', 'int'));
-               $this->assertEquals('String', $this->validatorResolver->_call('unifyDataType', 'string'));
-               $this->assertEquals('Array', $this->validatorResolver->_call('unifyDataType', 'array'));
-               $this->assertEquals('Float', $this->validatorResolver->_call('unifyDataType', 'float'));
-               $this->assertEquals('Float', $this->validatorResolver->_call('unifyDataType', 'double'));
-               $this->assertEquals('Boolean', $this->validatorResolver->_call('unifyDataType', 'boolean'));
-               $this->assertEquals('Boolean', $this->validatorResolver->_call('unifyDataType', 'bool'));
-               $this->assertEquals('Boolean', $this->validatorResolver->_call('unifyDataType', 'bool'));
-               $this->assertEquals('Number', $this->validatorResolver->_call('unifyDataType', 'number'));
-               $this->assertEquals('Number', $this->validatorResolver->_call('unifyDataType', 'numeric'));
+       public function getValidatorTypeCorrectlyRenamesPhpDataTypes() {
+               $this->assertEquals('Integer', $this->validatorResolver->_call('getValidatorType', 'integer'));
+               $this->assertEquals('Integer', $this->validatorResolver->_call('getValidatorType', 'int'));
+               $this->assertEquals('String', $this->validatorResolver->_call('getValidatorType', 'string'));
+               $this->assertEquals('Array', $this->validatorResolver->_call('getValidatorType', 'array'));
+               $this->assertEquals('Float', $this->validatorResolver->_call('getValidatorType', 'float'));
+               $this->assertEquals('Float', $this->validatorResolver->_call('getValidatorType', 'double'));
+               $this->assertEquals('Boolean', $this->validatorResolver->_call('getValidatorType', 'boolean'));
+               $this->assertEquals('Boolean', $this->validatorResolver->_call('getValidatorType', 'bool'));
+               $this->assertEquals('Boolean', $this->validatorResolver->_call('getValidatorType', 'bool'));
+               $this->assertEquals('Number', $this->validatorResolver->_call('getValidatorType', 'number'));
+               $this->assertEquals('Number', $this->validatorResolver->_call('getValidatorType', 'numeric'));
        }
 
        /**
         * @test
         * @author Bastian Waidelich <bastian@typo3.org>
         */
-       public function unifyDataTypeRenamesMixedToRaw() {
-               $this->assertEquals('Raw', $this->validatorResolver->_call('unifyDataType', 'mixed'));
+       public function getValidatorTypeRenamesMixedToRaw() {
+               $this->assertEquals('Raw', $this->validatorResolver->_call('getValidatorType', 'mixed'));
        }
 
        /**