class DisjunctionValidator extends AbstractCompositeValidator (View source)

Validator to chain many validators in a disjunction (logical or).

Properties

protected array $supportedOptions

This contains the supported options, their default values and descriptions.

from  AbstractCompositeValidator
protected array $options from  AbstractCompositeValidator
protected SplObjectStorage $validators from  AbstractCompositeValidator
protected SplObjectStorage $validatedInstancesContainer from  AbstractCompositeValidator

Methods

__construct(array $options = [])

Constructs the composite validator and sets validation options

void
setValidatedInstancesContainer(SplObjectStorage $validatedInstancesContainer)

Allows to set a container to keep track of validated instances.

void
addValidator(ValidatorInterface $validator)

Adds a new validator to the conjunction.

removeValidator(ValidatorInterface $validator)

Removes the specified validator.

int
count()

Returns the number of validators contained in this conjunction.

getValidators()

Returns the child validators of this Composite Validator

array
getOptions()

Returns the options for this validator

validate(mixed $value)

Checks if the given value is valid according to the validators of the disjunction.

Details

__construct(array $options = [])

Constructs the composite validator and sets validation options

Parameters

array $options

Options for the validator

Exceptions

InvalidValidationOptionsException

void setValidatedInstancesContainer(SplObjectStorage $validatedInstancesContainer)

Allows to set a container to keep track of validated instances.

Parameters

SplObjectStorage $validatedInstancesContainer

A container to keep track of validated instances

Return Value

void

void addValidator(ValidatorInterface $validator)

Adds a new validator to the conjunction.

Parameters

ValidatorInterface $validator

The validator that should be added

Return Value

void

removeValidator(ValidatorInterface $validator)

Removes the specified validator.

Parameters

ValidatorInterface $validator

The validator to remove

Exceptions

NoSuchValidatorException

int count()

Returns the number of validators contained in this conjunction.

Return Value

int

The number of validators

SplObjectStorage getValidators()

Returns the child validators of this Composite Validator

Return Value

SplObjectStorage

array getOptions()

Returns the options for this validator

Return Value

array

Result validate(mixed $value)

Checks if the given value is valid according to the validators of the disjunction.

So only one validator has to be valid, to make the whole disjunction valid. Errors are only returned if all validators failed.

Parameters

mixed $value

The value that should be validated

Return Value

Result