‪TYPO3CMS  9.5
TYPO3\CMS\Extbase\Validation\ValidatorResolver Class Reference
Inheritance diagram for TYPO3\CMS\Extbase\Validation\ValidatorResolver:
TYPO3\CMS\Core\SingletonInterface

Public Member Functions

 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
TYPO3 CMS Extbase Validation Validator ValidatorInterface createValidator ($validatorType, array $validatorOptions=[])
 
ConjunctionValidator getBaseValidatorConjunction ($targetClassName)
 
ConjunctionValidator[] buildMethodArgumentsValidatorConjunctions ($className, $methodName, array $methodParameters=null, array $methodValidateAnnotations=null)
 
array parseValidatorAnnotation ($validateValue)
 
string resolveValidatorObjectName ($validatorName)
 
array getMethodValidateAnnotations ($className, $methodName)
 

Public Attributes

const PATTERN_MATCH_VALIDATORS
 
const PATTERN_MATCH_VALIDATOROPTIONS
 

Protected Member Functions

TYPO3 CMS Extbase Validation Validator GenericObjectValidator buildSubObjectValidator (array $objectPath, \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator)
 
 buildBaseValidatorConjunction ($indexKey, $targetClassName, array $validationGroups=[])
 
 addCustomValidators ($targetClassName, ConjunctionValidator &$conjunctionValidator)
 
array parseValidatorOptions ($rawValidatorOptions)
 
 unquoteString (&$quotedValue)
 
string getValidatorType ($type)
 

Protected Attributes

TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
 
TYPO3 CMS Extbase Reflection ReflectionService $reflectionService
 
array $baseValidatorConjunctions = array( )
 

Detailed Description

Validator resolver to automatically find an appropriate validator for a given subject

only to be used within Extbase, not part of TYPO3 Core API.

Definition at line 28 of file ValidatorResolver.php.

Member Function Documentation

◆ addCustomValidators()

TYPO3\CMS\Extbase\Validation\ValidatorResolver::addCustomValidators (   $targetClassName,
ConjunctionValidator $conjunctionValidator 
)
protected

This adds custom validators to the passed $conjunctionValidator.

A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and append 'Validator'". If found, it will be added to the $conjunctionValidator.

In addition canValidate() will be called on all implementations of the ObjectValidatorInterface to find all validators that could validate the target. The one with the highest priority will be added as well. If multiple validators have the same priority, which one will be added is not deterministic.

Parameters
string$targetClassName
ConjunctionValidator$conjunctionValidator

Definition at line 356 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\addValidator(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\createValidator(), and TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToValidatorName().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildBaseValidatorConjunction().

◆ buildBaseValidatorConjunction()

TYPO3\CMS\Extbase\Validation\ValidatorResolver::buildBaseValidatorConjunction (   $indexKey,
  $targetClassName,
array  $validationGroups = [] 
)
protected

Builds a base validator conjunction for the given data type.

The base validation rules are those which were declared directly in a class (typically a model) through some validate annotations on properties.

If a property holds a class for which a base validator exists, that property will be checked as well, regardless of a validate annotation

Additionally, if a custom validator was defined for the class in question, it will be added to the end of the conjunction. A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and append 'Validator'".

Example: $targetClassName is TYPO3\Foo\Domain\Model\Quux, then the validator will be found if it has the name TYPO3\Foo\Domain\Validator\QuuxValidator

Parameters
string$indexKey‪The key to use as index in $this->baseValidatorConjunctions; calculated from target class name and validation groups
string$targetClassName‪The data type to build the validation conjunction for. Needs to be the fully qualified class name.
array$validationGroups‪The validation groups to build the validator for
Exceptions

Definition at line 279 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\addCustomValidators(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\createValidator(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\getBaseValidatorConjunction(), TYPO3\CMS\Extbase\Utility\TypeHandlingUtility\isCollectionType(), TYPO3\CMS\Extbase\Utility\TypeHandlingUtility\isCoreType(), and TYPO3\CMS\Extbase\Utility\TypeHandlingUtility\isSimpleType().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\getBaseValidatorConjunction().

◆ buildMethodArgumentsValidatorConjunctions()

ConjunctionValidator [] TYPO3\CMS\Extbase\Validation\ValidatorResolver::buildMethodArgumentsValidatorConjunctions (   $className,
  $methodName,
array  $methodParameters = null,
array  $methodValidateAnnotations = null 
)

Detects and registers any validators for arguments:

  • ‪by the data type specified in the param annotations
  • ‪additional validators specified in the validate annotations of a method
Parameters
string$className
string$methodName
array$methodParameters‪Optional pre-compiled array of method parameters
array$methodValidateAnnotations‪Optional pre-compiled array of validate annotations (as array)
Returns
‪ConjunctionValidator[] An Array of ValidatorConjunctions for each method parameters.
Exceptions

Definition at line 157 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildSubObjectValidator(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\createValidator(), and TYPO3\CMS\Extbase\Validation\ValidatorResolver\getMethodValidateAnnotations().

Referenced by TYPO3\CMS\Extbase\Tests\UnitDeprecated\Validation\ValidatorResolverTest\buildMethodArgumentsValidatorConjunctionsBuildsAConjunctionFromValidateAnnotationsOfTheSpecifiedMethod(), TYPO3\CMS\Extbase\Tests\UnitDeprecated\Validation\ValidatorResolverTest\buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments(), and TYPO3\CMS\Extbase\Tests\UnitDeprecated\Validation\ValidatorResolverTest\buildMethodArgumentsValidatorConjunctionsThrowsExceptionIfValidationAnnotationForNonExistingArgumentExists().

◆ buildSubObjectValidator()

TYPO3 CMS Extbase Validation Validator GenericObjectValidator TYPO3\CMS\Extbase\Validation\ValidatorResolver::buildSubObjectValidator ( array  $objectPath,
\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface  $propertyValidator 
)
protected

Builds a chain of nested object validators by specification of the given object path.

Parameters
array$objectPath‪The object path
\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface$propertyValidator‪The validator which should be added to the property specified by objectPath
Returns
‪\TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator
Deprecated:
‪since TYPO3 v9, will be removed in TYPO3 v10.0.

Definition at line 235 of file ValidatorResolver.php.

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildMethodArgumentsValidatorConjunctions().

◆ createValidator()

TYPO3 CMS Extbase Validation Validator ValidatorInterface TYPO3\CMS\Extbase\Validation\ValidatorResolver::createValidator (   $validatorType,
array  $validatorOptions = [] 
)

Get a validator for a given data type. Returns a validator implementing the \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface or NULL if no validator could be resolved.

Parameters
string$validatorType‪Either one of the built-in data types or fully qualified validator class name
array$validatorOptions‪Options to be passed to the validator
Returns
‪\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface Validator or NULL if none found.
Todo:
‪remove throwing Exceptions in resolveValidatorObjectName

Definition at line 102 of file ValidatorResolver.php.

References $validator, and TYPO3\CMS\Extbase\Validation\ValidatorResolver\resolveValidatorObjectName().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\addCustomValidators(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildBaseValidatorConjunction(), and TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildMethodArgumentsValidatorConjunctions().

◆ getBaseValidatorConjunction()

ConjunctionValidator TYPO3\CMS\Extbase\Validation\ValidatorResolver::getBaseValidatorConjunction (   $targetClassName)

Resolves and returns the base validator conjunction for the given data type.

If no validator could be resolved (which usually means that no validation is necessary), NULL is returned.

Parameters
string$targetClassName‪The data type to search a validator for. Usually the fully qualified object name
Returns
‪ConjunctionValidator The validator conjunction or NULL

Definition at line 133 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildBaseValidatorConjunction().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildBaseValidatorConjunction().

◆ getMethodValidateAnnotations()

array TYPO3\CMS\Extbase\Validation\ValidatorResolver::getMethodValidateAnnotations (   $className,
  $methodName 
)

Temporary replacement for $this->reflectionService->getMethodAnnotations()

Parameters
string$className
string$methodName
Returns
‪array
Deprecated:
‪Helper, remove in TYPO3 v10.0 together with buildMethodArgumentsValidatorConjunctions()

Definition at line 553 of file ValidatorResolver.php.

References $validator, and TYPO3\CMS\Extbase\Validation\ValidatorResolver\parseValidatorAnnotation().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildMethodArgumentsValidatorConjunctions().

◆ getValidatorType()

string TYPO3\CMS\Extbase\Validation\ValidatorResolver::getValidatorType (   $type)
protected

Used to map PHP types to validator types.

Parameters
string$type‪Data type to unify
Returns
‪string unified data type

Definition at line 520 of file ValidatorResolver.php.

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\resolveValidatorObjectName().

◆ injectObjectManager()

TYPO3\CMS\Extbase\Validation\ValidatorResolver::injectObjectManager ( \TYPO3\CMS\Extbase\Object\ObjectManagerInterface  $objectManager)
Parameters
\TYPO3\CMS\Extbase\Object\ObjectManagerInterface$objectManager

Definition at line 80 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\$objectManager.

◆ injectReflectionService()

TYPO3\CMS\Extbase\Validation\ValidatorResolver::injectReflectionService ( \TYPO3\CMS\Extbase\Reflection\ReflectionService  $reflectionService)
Parameters
\TYPO3\CMS\Extbase\Reflection\ReflectionService$reflectionService

Definition at line 88 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\$reflectionService.

◆ parseValidatorAnnotation()

array TYPO3\CMS\Extbase\Validation\ValidatorResolver::parseValidatorAnnotation (   $validateValue)

Parses the validator options given in @validate annotations.

Parameters
string$validateValue
Returns
‪array
Deprecated:
‪Helper, remove in TYPO3 v10.0 together with the deprecated consumer methods

Definition at line 377 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\parseValidatorOptions().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\getMethodValidateAnnotations().

◆ parseValidatorOptions()

array TYPO3\CMS\Extbase\Validation\ValidatorResolver::parseValidatorOptions (   $rawValidatorOptions)
protected

Parses $rawValidatorOptions not containing quoted option values. $rawValidatorOptions will be an empty string afterwards (pass by ref!).

Parameters
string$rawValidatorOptions
Returns
‪array An array of optionName/optionValue pairs
Deprecated:
‪since TYPO3 v9, will be removed in TYPO3 v10.0.

Definition at line 411 of file ValidatorResolver.php.

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\parseValidatorAnnotation().

◆ resolveValidatorObjectName()

string TYPO3\CMS\Extbase\Validation\ValidatorResolver::resolveValidatorObjectName (   $validatorName)

Returns an object of an appropriate validator for the given class. If no validator is available FALSE is returned

Parameters
string$validatorName‪Either the fully qualified class name of the validator or the short name of a built-in validator
Exceptions
Exception

Definition at line 465 of file ValidatorResolver.php.

References TYPO3\CMS\Extbase\Validation\ValidatorResolver\getValidatorType().

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\createValidator().

◆ unquoteString()

TYPO3\CMS\Extbase\Validation\ValidatorResolver::unquoteString ( $quotedValue)
protected

Removes escapings from a given argument string and trims the outermost quotes.

This method is meant as a helper for regular expression results.

Parameters
string&$quotedValue‪Value to unquote
Deprecated:
‪since TYPO3 v9, will be removed in TYPO3 v10.0.

Definition at line 437 of file ValidatorResolver.php.

Member Data Documentation

◆ $baseValidatorConjunctions

array TYPO3\CMS\Extbase\Validation\ValidatorResolver::$baseValidatorConjunctions = array( )
protected

Definition at line 75 of file ValidatorResolver.php.

◆ $objectManager

TYPO3 CMS Extbase Object ObjectManagerInterface TYPO3\CMS\Extbase\Validation\ValidatorResolver::$objectManager
protected

◆ $reflectionService

TYPO3 CMS Extbase Reflection ReflectionService TYPO3\CMS\Extbase\Validation\ValidatorResolver::$reflectionService
protected

◆ PATTERN_MATCH_VALIDATOROPTIONS

const TYPO3\CMS\Extbase\Validation\ValidatorResolver::PATTERN_MATCH_VALIDATOROPTIONS
Initial value:
= '/
\s*
(?P<optionName>[a-z0-9]+)
\s*=\s*
(?P<optionValue>
"(?:\\\\"|[^"])*"
|\'(?:\\\\\'|[^\'])*\'
|(?:\s|[^,"\']*)
)
/ixS'

Definition at line 54 of file ValidatorResolver.php.

◆ PATTERN_MATCH_VALIDATORS

const TYPO3\CMS\Extbase\Validation\ValidatorResolver::PATTERN_MATCH_VALIDATORS
Initial value:
= '/
(?:^|,\s*)
(?P<validatorName>[a-z0-9:.\\\\]+)
\s*
(?:\‍(
(?P<validatorOptions>(?:\s*[a-z0-9]+\s*=\s*(?:
"(?:\\\\"|[^"])*"
|\'(?:\\\\\'|[^\'])*\'
|(?:\s|[^,"\']*)
)(?:\s|,)*)*)
\‍))?
/ixS'

Definition at line 36 of file ValidatorResolver.php.