TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ValidatorResolver Class Reference
Inheritance diagram for ValidatorResolver:
SingletonInterface

Public Member Functions

 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 createValidator ($validatorType, array $validatorOptions=array())
 
 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 = array()
 

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 (   $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 AbstractCompositeValidator\addValidator(), ValidatorResolver\createValidator(), and ClassNamingUtility\translateModelNameToValidatorName().

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$objectPathThe object path
\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface$propertyValidatorThe validator which should be added to the property specified by objectPath
Returns

Definition at line 226 of file ValidatorResolver.php.

createValidator (   $validatorType,
array  $validatorOptions = array() 
)

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 GeneralUtility\devLog(), ValidatorResolver\resolveValidatorObjectName(), and GeneralUtility\SYSLOG_SEVERITY_INFO.

Referenced by ValidatorResolver\addCustomValidators().

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.

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 ValidatorResolver\parseValidatorAnnotation().

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 ValidatorResolver\resolveValidatorObjectName().

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

Definition at line 80 of file ValidatorResolver.php.

References ValidatorResolver\$objectManager.

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

Definition at line 88 of file ValidatorResolver.php.

References ValidatorResolver\$reflectionService.

parseValidatorAnnotation (   $validateValue)
protected

Parses the validator options given in annotations.

Parameters
string$validateValue
Returns
array

Definition at line 370 of file ValidatorResolver.php.

References ValidatorResolver\parseValidatorOptions().

Referenced by ValidatorResolver\getMethodValidateAnnotations().

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 ValidatorResolver\parseValidatorAnnotation().

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\NoSuchValidatorException
Returns
string Name of the validator object

Definition at line 441 of file ValidatorResolver.php.

References ValidatorResolver\getValidatorType().

Referenced by ValidatorResolver\createValidator().

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 = array()
protected

Definition at line 75 of file ValidatorResolver.php.

$objectManager
protected

Definition at line 65 of file ValidatorResolver.php.

Referenced by ValidatorResolver\injectObjectManager().

$reflectionService
protected

Definition at line 70 of file ValidatorResolver.php.

Referenced by ValidatorResolver\injectReflectionService().

const 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.

const 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.