From af610eb397ae7a04520d8efb15484967431aa71f Mon Sep 17 00:00:00 2001 From: Alexander Schnitzler <alex.schnitzler@typovision.de> Date: Sun, 2 Jun 2013 13:36:59 +0200 Subject: [PATCH] [TASK] Make preperations for backporting Flow validation api 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 --- typo3/sysext/extbase/Classes/Error/Result.php | 134 ++++++++++++++++-- .../Mvc/Controller/ActionController.php | 24 +++- .../extbase/Classes/Validation/Error.php | 9 +- .../extbase/Classes/Validation/Exception.php | 3 + .../Validator/AbstractCompositeValidator.php | 47 +++++- .../Validator/AbstractValidator.php | 35 +++++ .../Validator/AlphanumericValidator.php | 4 +- .../Validator/ConjunctionValidator.php | 8 +- .../Validator/DateTimeValidator.php | 7 +- .../Validator/DisjunctionValidator.php | 9 +- .../Validator/EmailAddressValidator.php | 5 +- .../Validation/Validator/FloatValidator.php | 7 +- .../Validation/Validator/IntegerValidator.php | 7 +- .../Validator/NotEmptyValidator.php | 7 +- .../Validator/NumberRangeValidator.php | 5 +- .../Validation/Validator/NumberValidator.php | 7 +- .../Validator/ObjectValidatorInterface.php | 10 +- .../Validation/Validator/RawValidator.php | 7 +- .../Validator/RegularExpressionValidator.php | 8 +- .../Validator/StringLengthValidator.php | 7 +- .../Validation/Validator/StringValidator.php | 7 +- .../Validation/Validator/TextValidator.php | 7 +- .../Validator/ValidatorInterface.php | 13 +- .../Classes/Validation/ValidatorResolver.php | 28 ++-- .../extbase/Tests/Unit/Error/ResultTest.php | 2 +- .../Unit/Validation/ValidatorResolverTest.php | 34 ++--- 26 files changed, 346 insertions(+), 95 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Error/Result.php b/typo3/sysext/extbase/Classes/Error/Result.php index b03a735a3976..02cfdb50e230 100644 --- a/typo3/sysext/extbase/Classes/Error/Result.php +++ b/typo3/sysext/extbase/Classes/Error/Result.php @@ -33,16 +33,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 * @@ -50,6 +68,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 * @@ -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,13 +222,81 @@ 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! * @@ -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); } } diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php index e7da4e5c189f..5c659a3a9548 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php +++ b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php @@ -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 +?> diff --git a/typo3/sysext/extbase/Classes/Validation/Error.php b/typo3/sysext/extbase/Classes/Validation/Error.php index c2fddd1f03d6..7a3c6016ca77 100644 --- a/typo3/sysext/extbase/Classes/Validation/Error.php +++ b/typo3/sysext/extbase/Classes/Validation/Error.php @@ -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; } diff --git a/typo3/sysext/extbase/Classes/Validation/Exception.php b/typo3/sysext/extbase/Classes/Validation/Exception.php index 83b755fe3248..0518d7110e3a 100644 --- a/typo3/sysext/extbase/Classes/Validation/Exception.php +++ b/typo3/sysext/extbase/Classes/Validation/Exception.php @@ -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 { diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php index fc985784dc1a..c7879a3390ef 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/AbstractCompositeValidator.php @@ -34,6 +34,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 */ @@ -44,13 +51,20 @@ 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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php index b2992f8c17af..93ac1d8c9e8e 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/AbstractValidator.php @@ -32,6 +32,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 */ @@ -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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php index 163584000a4c..7cb6d8e18786 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/AlphanumericValidator.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php index 6f8e531f9887..226381ce171f 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/ConjunctionValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php index 252bdf602505..a003b36a3103 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/DateTimeValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php index 7cb2327b295e..24e66993f9fd 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/DisjunctionValidator.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php index 2a66d5ec0603..d8cd99b4ca77 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php index 7c15b33b0f48..a61d7bfb6229 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/FloatValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php index 69eb98c81131..7b7120acf303 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/IntegerValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php index 4759a28dd66b..97ad0232c574 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/NotEmptyValidator.php @@ -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). diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php index 83b0691d6eca..06f39be1879a 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/NumberRangeValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php index 309c2bd1bbce..44bda860e892 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/NumberValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php b/typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php index c94f996b3937..fe4ca7be8b4e 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/ObjectValidatorInterface.php @@ -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); } diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php index f794c4f77ec8..3304c373d672 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/RawValidator.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php index 03b03345b5c5..110b76eb9936 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/RegularExpressionValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php index f28cda62f928..184ac38f0689 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/StringLengthValidator.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php index 43a46b8b76fa..ae9b70a25e25 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/StringValidator.php @@ -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. diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php b/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php index 39554de29d6f..20e9de5ab0d0 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/TextValidator.php @@ -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). diff --git a/typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php b/typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php index 07244b85d011..ceec3b681dc6 100644 --- a/typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php +++ b/typo3/sysext/extbase/Classes/Validation/Validator/ValidatorInterface.php @@ -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 */ diff --git a/typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php b/typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php index cf03addecc69..f350c44859ec 100644 --- a/typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php +++ b/typo3/sysext/extbase/Classes/Validation/ValidatorResolver.php @@ -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'; diff --git a/typo3/sysext/extbase/Tests/Unit/Error/ResultTest.php b/typo3/sysext/extbase/Tests/Unit/Error/ResultTest.php index 71708866d1d5..c899961768ee 100644 --- a/typo3/sysext/extbase/Tests/Unit/Error/ResultTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Error/ResultTest.php @@ -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); diff --git a/typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php b/typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php index f82c2244eae7..f06c1e777b57 100644 --- a/typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Validation/ValidatorResolverTest.php @@ -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')); } /** -- GitLab