TYPO3 CMS  TYPO3_7-6
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)
 
 createValidator ($validatorType, array $validatorOptions=[])
 
 getBaseValidatorConjunction ($targetClassName)
 
 getMethodValidateAnnotations ($className, $methodName)
 

Public Attributes

const PATTERN_MATCH_VALIDATORS
 
const PATTERN_MATCH_VALIDATOROPTIONS
 

Protected Member Functions

 buildSubObjectValidator (array $objectPath, \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator)
 
 addCustomValidators ($targetClassName, ConjunctionValidator &$conjunctionValidator)
 
 parseValidatorAnnotation ($validateValue)
 
 parseValidatorOptions ($rawValidatorOptions)
 
 unquoteString (&$quotedValue)
 
 resolveValidatorObjectName ($validatorName)
 
 getValidatorType ($type)
 

Protected Attributes

 $objectManager
 
 $reflectionService
 
 $baseValidatorConjunctions = []
 

Detailed Description

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

Definition at line 26 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
Returns
NULL|Validator

Definition at line 349 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\buildSubObjectValidator().

◆ buildSubObjectValidator()

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

◆ createValidator()

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

Get a validator for a given data type. Returns a validator implementing the or NULL if no validator could be resolved.

Parameters
string$validatorTypeEither one of the built-in data types or fully qualified validator class name
array$validatorOptionsOptions to be passed to the validator
Returns
Validator or NULL if none found.
Todo:
remove throwing Exceptions in resolveValidatorObjectName

Definition at line 102 of file ValidatorResolver.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\devLog(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\resolveValidatorObjectName(), and TYPO3\CMS\Core\Utility\GeneralUtility\SYSLOG_SEVERITY_INFO.

Referenced by TYPO3\CMS\Extbase\Validation\ValidatorResolver\addCustomValidators(), TYPO3\CMS\Extbase\Validation\ValidatorResolver\buildSubObjectValidator(), and TYPO3\CMS\Extbase\Validation\ValidatorResolver\getBaseValidatorConjunction().

◆ getBaseValidatorConjunction()

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$targetClassNameThe data type to search a validator for. Usually the fully qualified object name
Returns
ConjunctionValidator The validator conjunction or NULL

Definition at line 132 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\Validation\ValidatorResolver\buildSubObjectValidator().

◆ getMethodValidateAnnotations()

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

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

Parameters
string$className
string$methodName
Returns
array

Definition at line 527 of file ValidatorResolver.php.

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

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

◆ getValidatorType()

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

Used to map PHP types to validator types.

Parameters
string$typeData type to unify
Returns
string unified data type

Definition at line 495 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()

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

Parses the validator options given in annotations.

Parameters
string$validateValue
Returns
array

Definition at line 370 of file ValidatorResolver.php.

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

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

◆ parseValidatorOptions()

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

Definition at line 398 of file ValidatorResolver.php.

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

◆ resolveValidatorObjectName()

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

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

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

Definition at line 441 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&$quotedValueValue to unquote
Returns
void

Definition at line 419 of file ValidatorResolver.php.

Member Data Documentation

◆ $baseValidatorConjunctions

TYPO3\CMS\Extbase\Validation\ValidatorResolver::$baseValidatorConjunctions = []
protected

Definition at line 75 of file ValidatorResolver.php.

◆ $objectManager

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

◆ $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 51 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 34 of file ValidatorResolver.php.