class GenericObjectValidator extends AbstractValidator implements ObjectValidatorInterface (View source)

A generic object validator which allows for specifying property validators.

Properties

protected bool $acceptsEmptyValues

Specifies whether this validator accepts empty values.

from  AbstractValidator
protected array $supportedOptions
protected array $options from  AbstractValidator
protected Result[] $resultStack from  AbstractValidator
protected array $propertyValidators
protected SplObjectStorage $validatedInstancesContainer

Methods

__construct(array $options = [])

Constructs the validator and sets validation options

pushResult()

Push a new Result onto the Result stack and return it in order to fix cyclic calls to a single validator.

popResult()

Pop and return the current Result from the stack and make $this->result point to the last Result again.

Result|null
getResult()

Get the current Result for this validation invocation. Use this inside your isValid() implementation to e.g. merge results together into the current one.

validate(mixed $value)

Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.

void
isValid(mixed $object)

Checks if the given value is valid according to the property validators.

void
addError(string $message, int $code, array $arguments = [])

Creates a new validation error object and adds it to $this->errors

array
getOptions()

Returns the options of this validator

bool
isEmpty(mixed $value)

No description

void
setValidatedInstancesContainer(SplObjectStorage $validatedInstancesContainer)

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

bool
isUninitializedProxy($object)

No description

bool
isValidatedAlready(object $object)

No description

mixed
getPropertyValue(object $object, string $propertyName)

Load the property value to be used for validation.

null|Result
checkProperty(mixed $value, array $validators)

Checks if the specified property of the given object is valid, and adds found errors to the $messages object.

void
addPropertyValidator(string $propertyName, ValidatorInterface $validator)

Adds the given validator for validation of the specified property.

array
getPropertyValidators(string $propertyName = null)

Returns all property validators - or only validators of the specified property

Details

__construct(array $options = [])

Constructs the validator and sets validation options

Parameters

array $options

Options for the validator

Exceptions

InvalidValidationOptionsException

protected Result pushResult()

Since: Flow 4.3

Push a new Result onto the Result stack and return it in order to fix cyclic calls to a single validator.

protected Result popResult()

Since: Flow 4.3

Pop and return the current Result from the stack and make $this->result point to the last Result again.

Return Value

Result

protected Result|null getResult()

Since: Flow 6.0

Get the current Result for this validation invocation. Use this inside your isValid() implementation to e.g. merge results together into the current one.

Return Value

Result|null

Result validate(mixed $value)

Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.

Parameters

mixed $value

The value that should be validated

Return Value

Result

Exceptions

InvalidValidationOptionsException

protected void isValid(mixed $object)

Checks if the given value is valid according to the property validators.

Parameters

mixed $object

The value that should be validated

Return Value

void

protected void addError(string $message, int $code, array $arguments = [])

Creates a new validation error object and adds it to $this->errors

Parameters

string $message

The error message

int $code

The error code (a unix timestamp)

array $arguments

Arguments to be replaced in message

Return Value

void

array getOptions()

Returns the options of this validator

Return Value

array

final protected bool isEmpty(mixed $value)

No description

Parameters

mixed $value

Return Value

bool

true if the given $value is NULL or an empty string ('')

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

protected bool isUninitializedProxy($object)

No description

Parameters

$object

Return Value

bool

protected bool isValidatedAlready(object $object)

No description

Parameters

object $object

Return Value

bool

protected mixed getPropertyValue(object $object, string $propertyName)

Load the property value to be used for validation.

In case the object is a doctrine proxy, we need to load the real instance first.

Parameters

object $object
string $propertyName

Return Value

mixed

protected null|Result checkProperty(mixed $value, array $validators)

Checks if the specified property of the given object is valid, and adds found errors to the $messages object.

Parameters

mixed $value

The value to be validated

array $validators

The validators to be called on the value

Return Value

null|Result

void addPropertyValidator(string $propertyName, ValidatorInterface $validator)

Adds the given validator for validation of the specified property.

Parameters

string $propertyName

Name of the property to validate

ValidatorInterface $validator

The property validator

Return Value

void

array getPropertyValidators(string $propertyName = null)

Returns all property validators - or only validators of the specified property

Parameters

string $propertyName

Name of the property to return validators for

Return Value

array

An array of validators