class Validator (View source)

Validatable object constraints validator.

Constants

private CLASS_ATTRIBUTE

private CONSTANT_ATTRIBUTE

private METHOD_ATTRIBUTE

private PROPERTY_ATTRIBUTE

Properties

protected Constraint> $constraints

Validatable object constraints.

protected Result> $errors

Validatable object validation errors.

static protected Reflector|Reflector[]> $reflections

Validatable objects reflections cache.

protected Result> $results

Validatable object validation results.

Methods

__construct(ValidatableObjectInterface $object)

Validator constructor.

void
check()

Checks object constraints and throws an exception if validation failed.

void
checkAttributes(array $attributes, string $type, string $name, mixed $value, string|null $cacheKey = null)

Checks attributes of the passed validatable object reflection.

void
checkConstraint(Constraint $constraint, string $type, string $name, mixed $value)

Checks constraints of the passed validatable object reflection.

never
fail(Result ...$violation)

No description

array
getErrors()

Returns object constraints validation errors.

string
getMemoizationKey(string $reflection, string $target = 'class', string $prefix = '::', string $suffix = '')

Returns a unique identifier for the specifed reflection class name.

array
getResults()

Returns object constraints validation results.

array
validate()

Validates object constraints and returns validation results.

void
validateClass(ReflectionClass $reflection)

Validates class attributes of the passed validatable object reflection.

void
validateConstants(ReflectionClass $reflection)

Validates constants attributes of the passed validatable object reflection.

void
validateMethods(ReflectionClass $reflection)

Validates methods attributes of the passed validatable object reflection.

void
validateProperties(ReflectionClass $reflection)

Validates properties attributes of the passed validatable object reflection.

Details

__construct(ValidatableObjectInterface $object)

Validator constructor.

Parameters

ValidatableObjectInterface $object

void check()

Checks object constraints and throws an exception if validation failed.

protected void checkAttributes(array $attributes, string $type, string $name, mixed $value, string|null $cacheKey = null)

Checks attributes of the passed validatable object reflection.

Parameters

array $attributes

the reflection on the validatable object attributes.

string $type

The type of the attribute.

string $name

The name of the field.

mixed $value

The value of the field.

string|null $cacheKey

The cache of the object.

Return Value

void

Exceptions

ValidationFailedException

protected void checkConstraint(Constraint $constraint, string $type, string $name, mixed $value)

Checks constraints of the passed validatable object reflection.

Parameters

Constraint $constraint

The constraint to check.

string $type

The type of the subject.

string $name

The name of the subject.

mixed $value

The value of the subject.

Return Value

void

Exceptions

ValidationFailedException

private never fail(Result ...$violation)

No description

Parameters

Result ...$violation

Return Value

never

array getErrors()

Returns object constraints validation errors.

Return Value

array

private string getMemoizationKey(string $reflection, string $target = 'class', string $prefix = '::', string $suffix = '')

Returns a unique identifier for the specifed reflection class name.

Parameters

string $reflection

Reflection class name.

string $target

The target of the reflection.

string $prefix

The prefix of the target.

string $suffix

The suffix of the target.

Return Value

string

array getResults()

Returns object constraints validation results.

Return Value

array

array validate()

Validates object constraints and returns validation results.

Return Value

array

protected void validateClass(ReflectionClass $reflection)

Validates class attributes of the passed validatable object reflection.

Parameters

ReflectionClass $reflection

The reflection on the validatable object.

Return Value

void

Exceptions

ValidationFailedException

protected void validateConstants(ReflectionClass $reflection)

Validates constants attributes of the passed validatable object reflection.

Parameters

ReflectionClass $reflection

The reflection on the validatable object.

Return Value

void

Exceptions

ValidationFailedException

protected void validateMethods(ReflectionClass $reflection)

Validates methods attributes of the passed validatable object reflection.

Parameters

ReflectionClass $reflection

The reflection on the validatable object.

Return Value

void

Exceptions

ValidationFailedException
ValidationLogicException

protected void validateProperties(ReflectionClass $reflection)

Validates properties attributes of the passed validatable object reflection.

Parameters

ReflectionClass $reflection

The reflection on the validatable object.

Return Value

void

Exceptions

ValidationFailedException