CollectionValidator extends GenericObjectValidator
A generic collection validator.
Table of Contents
Properties
- $acceptsEmptyValues : bool
- Specifies whether this validator accepts empty values.
- $options : array<string|int, mixed>
- $propertyValidators : array<string|int, SplObjectStorage>
- $result : Result
- $supportedOptions : array<string|int, mixed>
- $validatedInstancesContainer : SplObjectStorage
- $validatorResolver : ValidatorResolver
Methods
- __construct() : mixed
- Constructs the validator and sets validation options
- addPropertyValidator() : mixed
- Adds the given validator for validation of the specified property.
- canValidate() : bool
- Checks the given object can be validated by the validator implementation
- getOptions() : array<string|int, mixed>
- Returns the options of this validator
- getPropertyValidators() : array<string|int, mixed>
- Returns all property validators - or only validators of the specified property
- setValidatedInstancesContainer() : mixed
- Allows to set a container to keep track of validated instances.
- validate() : Result
- Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.
- addError() : mixed
- Creates a new validation error object and adds it to $this->result
- addErrorForProperty() : mixed
- Creates a new validation error object for a property and adds it to the proper sub result of $this->result
- checkProperty() : mixed
- Checks if the specified property of the given object is valid, and adds found errors to the $messages object.
- getPropertyValue() : mixed
- Load the property value to be used for validation.
- initializeDefaultOptions() : void
- Initialize default options.
- isEmpty() : bool
- isValid() : mixed
- Checks for a collection and if needed validates the items in the collection.
- isValidatedAlready() : bool
- markInstanceAsValidated() : void
- translateErrorMessage() : string
- Wrap static call to LocalizationUtility to simplify unit testing
Properties
$acceptsEmptyValues
Specifies whether this validator accepts empty values.
protected
bool
$acceptsEmptyValues
= true
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
$options
protected
array<string|int, mixed>
$options
= []
$propertyValidators
protected
array<string|int, SplObjectStorage>
$propertyValidators
= []
$result
protected
Result
$result
$supportedOptions
protected
array<string|int, mixed>
$supportedOptions
= ['elementValidator' => [null, 'The validator type to use for the collection elements', 'string'], 'elementType' => [null, 'The type of the elements in the collection', 'string'], 'validationGroups' => [null, 'The validation groups to link to', 'string']]
$validatedInstancesContainer
protected
SplObjectStorage
$validatedInstancesContainer
$validatorResolver
protected
ValidatorResolver
$validatorResolver
Methods
__construct()
Constructs the validator and sets validation options
public
__construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string|int, mixed> = []
-
Options for the validator
addPropertyValidator()
Adds the given validator for validation of the specified property.
public
addPropertyValidator(string $propertyName, ValidatorInterface $validator) : mixed
Parameters
- $propertyName : string
-
Name of the property to validate
- $validator : ValidatorInterface
-
The property validator
canValidate()
Checks the given object can be validated by the validator implementation
public
canValidate(mixed $object) : bool
Parameters
- $object : mixed
-
The object to be checked
Return values
bool —TRUE if the given value is an object
getOptions()
Returns the options of this validator
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getPropertyValidators()
Returns all property validators - or only validators of the specified property
public
getPropertyValidators([string $propertyName = null ]) : array<string|int, mixed>
Parameters
- $propertyName : string = null
-
Name of the property to return validators for
Return values
array<string|int, mixed> —An array of validators
setValidatedInstancesContainer()
Allows to set a container to keep track of validated instances.
public
setValidatedInstancesContainer(SplObjectStorage $validatedInstancesContainer) : mixed
Parameters
- $validatedInstancesContainer : SplObjectStorage
-
A container to keep track of validated instances
validate()
Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.
public
validate(mixed $value) : Result
Parameters
- $value : mixed
-
The value that should be validated
Return values
ResultaddError()
Creates a new validation error object and adds it to $this->result
protected
addError(string $message, int $code[, array<string|int, mixed> $arguments = [] ][, string $title = '' ]) : mixed
Parameters
- $message : string
-
The error message
- $code : int
-
The error code (a unix timestamp)
- $arguments : array<string|int, mixed> = []
-
Arguments to be replaced in message
- $title : string = ''
-
title of the error
addErrorForProperty()
Creates a new validation error object for a property and adds it to the proper sub result of $this->result
protected
addErrorForProperty(mixed $propertyPath, string $message, int $code[, array<string|int, mixed> $arguments = [] ][, string $title = '' ]) : mixed
Parameters
- $propertyPath : mixed
- $message : string
-
The error message
- $code : int
-
The error code (a unix timestamp)
- $arguments : array<string|int, mixed> = []
-
Arguments to be replaced in message
- $title : string = ''
-
title of the error
checkProperty()
Checks if the specified property of the given object is valid, and adds found errors to the $messages object.
protected
checkProperty(mixed $value, Traversable $validators, string $propertyName) : mixed
Parameters
- $value : mixed
-
The value to be validated
- $validators : Traversable
-
The validators to be called on the value
- $propertyName : string
-
Name of the property to check
getPropertyValue()
Load the property value to be used for validation.
protected
getPropertyValue(object $object, string $propertyName) : mixed
In case the object is a doctrine proxy, we need to load the real instance first.
Parameters
- $object : object
- $propertyName : string
initializeDefaultOptions()
Initialize default options.
protected
initializeDefaultOptions(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
Tags
isEmpty()
protected
final isEmpty(mixed $value) : bool
Parameters
- $value : mixed
Return values
bool —TRUE if the given $value is NULL or an empty string ('')
isValid()
Checks for a collection and if needed validates the items in the collection.
protected
isValid(mixed $value) : mixed
This is done with the specified element validator or a validator based on the given element type and validation group.
Either elementValidator or elementType must be given, otherwise validation will be skipped.
Parameters
- $value : mixed
-
A collection to be validated
isValidatedAlready()
protected
isValidatedAlready(object $object) : bool
Parameters
- $object : object
Return values
boolmarkInstanceAsValidated()
protected
markInstanceAsValidated(object $object) : void
Parameters
- $object : object
translateErrorMessage()
Wrap static call to LocalizationUtility to simplify unit testing
protected
translateErrorMessage(string $translateKey, string $extensionName[, array<string|int, mixed> $arguments = [] ]) : string
Parameters
- $translateKey : string
- $extensionName : string
- $arguments : array<string|int, mixed> = []