Documentation

RecursiveContextualValidator
in package
implements ContextualValidatorInterface

Recursive implementation of {@link ContextualValidatorInterface}.

Tags
author

Bernhard Schussek bschussek@gmail.com

Table of Contents

Interfaces

ContextualValidatorInterface
A validator in a specific execution context.

Properties

$context  : mixed
$defaultGroups  : array<string|int, mixed>
$defaultPropertyPath  : string
$metadataFactory  : mixed
$objectInitializers  : array<string|int, mixed>
$validatorFactory  : mixed

Methods

__construct()  : mixed
Creates a validator for the given context.
atPath()  : $this
Appends the given path to the property path of the context.
getViolations()  : ConstraintViolationListInterface
Returns the violations that have been generated so far in the context of the validator.
validate()  : $this
Validates a value against a constraint or a list of constraints.
validateProperty()  : $this
Validates a property of an object against the constraints specified for this property.
validatePropertyValue()  : $this
Validates a value against the constraints specified for an object's property.
normalizeGroups()  : array<string|int, string|GroupSequence>
Normalizes the given group or list of groups to an array.
generateCacheKey()  : string
stepThroughGroupSequence()  : mixed
Sequentially validates a node's value in each group of a group sequence.
validateClassNode()  : mixed
Validates a class node.
validateEachObjectIn()  : mixed
Validates each object in a collection against the constraints defined for their classes.
validateGenericNode()  : mixed
Validates a node that is not a class node.
validateInGroup()  : mixed
Validates a node's value against all constraints in the given group.
validateObject()  : mixed
Validates an object against the constraints defined for its class.

Properties

Methods

__construct()

Creates a validator for the given context.

public __construct(ExecutionContextInterface $context, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory[, array<string|int, ObjectInitializerInterface$objectInitializers = [] ]) : mixed
Parameters
$context : ExecutionContextInterface
$metadataFactory : MetadataFactoryInterface
$validatorFactory : ConstraintValidatorFactoryInterface
$objectInitializers : array<string|int, ObjectInitializerInterface> = []

The object initializers

atPath()

Appends the given path to the property path of the context.

public atPath(string $path) : $this
Parameters
$path : string
Return values
$this

validate()

Validates a value against a constraint or a list of constraints.

public validate(mixed $value[, Constraint|array<string|int, mixed> $constraints = null ][, string|GroupSequence|array<string|int, mixed> $groups = null ]) : $this
Parameters
$value : mixed

The value to validate

$constraints : Constraint|array<string|int, mixed> = null

The constraint(s) to validate against

$groups : string|GroupSequence|array<string|int, mixed> = null

The validation groups to validate. If none is given, "Default" is assumed

Return values
$this

validateProperty()

Validates a property of an object against the constraints specified for this property.

public validateProperty(object $object, string $propertyName[, string|GroupSequence|array<string|int, mixed> $groups = null ]) : $this
Parameters
$object : object
$propertyName : string

The name of the validated property

$groups : string|GroupSequence|array<string|int, mixed> = null

The validation groups to validate. If none is given, "Default" is assumed

Return values
$this

validatePropertyValue()

Validates a value against the constraints specified for an object's property.

public validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value[, string|GroupSequence|array<string|int, mixed> $groups = null ]) : $this
Parameters
$objectOrClass : object|string

The object or its class name

$propertyName : string

The name of the property

$value : mixed

The value to validate against the property's constraints

$groups : string|GroupSequence|array<string|int, mixed> = null

The validation groups to validate. If none is given, "Default" is assumed

Return values
$this

generateCacheKey()

private generateCacheKey(object $object[, bool $dependsOnPropertyPath = false ]) : string
Parameters
$object : object
$dependsOnPropertyPath : bool = false
Return values
string

stepThroughGroupSequence()

Sequentially validates a node's value in each group of a group sequence.

private stepThroughGroupSequence(mixed $value, object|null $object, string|null $cacheKey, MetadataInterface|null $metadata, string $propertyPath, int $traversalStrategy, GroupSequence $groupSequence, string|null $cascadedGroup, ExecutionContextInterface $context) : mixed

If any of the constraints generates a violation, subsequent groups in the group sequence are skipped.

Parameters
$value : mixed
$object : object|null
$cacheKey : string|null
$metadata : MetadataInterface|null
$propertyPath : string
$traversalStrategy : int
$groupSequence : GroupSequence
$cascadedGroup : string|null
$context : ExecutionContextInterface

validateClassNode()

Validates a class node.

private validateClassNode(object $object, string|null $cacheKey, ClassMetadataInterface $metadata, string $propertyPath, array<string|int, mixed> $groups, array<string|int, mixed>|null $cascadedGroups, int $traversalStrategy, ExecutionContextInterface $context) : mixed

A class node is a combination of an object with a instance. Each class node (conceptually) has zero or more succeeding property nodes:

(Article:class node)
           \
   ($title:property node)

This method validates the passed objects against all constraints defined at class level. It furthermore triggers the validation of each of the class' properties against the constraints for that property.

If the selected traversal strategy allows traversal, the object is iterated and each nested object is validated against its own constraints. The object is not traversed if traversal is disabled in the class metadata.

If the passed groups contain the group "Default", the validator will check whether the "Default" group has been replaced by a group sequence in the class metadata. If this is the case, the group sequence is validated instead.

Parameters
$object : object
$cacheKey : string|null
$metadata : ClassMetadataInterface
$propertyPath : string
$groups : array<string|int, mixed>
$cascadedGroups : array<string|int, mixed>|null
$traversalStrategy : int
$context : ExecutionContextInterface
Tags
throws
UnsupportedMetadataException

If a property metadata does not implement

throws
ConstraintDefinitionException

If traversal was enabled but the object does not implement

see
TraversalStrategy

validateEachObjectIn()

Validates each object in a collection against the constraints defined for their classes.

private validateEachObjectIn(iterable<string|int, mixed> $collection, string $propertyPath, array<string|int, mixed> $groups, ExecutionContextInterface $context) : mixed

Nested arrays are also iterated.

Parameters
$collection : iterable<string|int, mixed>
$propertyPath : string
$groups : array<string|int, mixed>
$context : ExecutionContextInterface

validateGenericNode()

Validates a node that is not a class node.

private validateGenericNode(mixed $value, object|null $object, string|null $cacheKey, MetadataInterface|null $metadata, string $propertyPath, array<string|int, mixed> $groups, array<string|int, mixed>|null $cascadedGroups, int $traversalStrategy, ExecutionContextInterface $context) : mixed

Currently, two such node types exist:

  • property nodes, which consist of the value of an object's property together with a instance
  • generic nodes, which consist of a value and some arbitrary constraints defined in a container

In both cases, the value is validated against all constraints defined in the passed metadata object. Then, if the value is an instance of and the selected traversal strategy permits it, the value is traversed and each nested object validated against its own constraints. If the value is an array, it is traversed regardless of the given strategy.

Parameters
$value : mixed
$object : object|null
$cacheKey : string|null
$metadata : MetadataInterface|null
$propertyPath : string
$groups : array<string|int, mixed>
$cascadedGroups : array<string|int, mixed>|null
$traversalStrategy : int
$context : ExecutionContextInterface
Tags
see
TraversalStrategy

validateObject()

Validates an object against the constraints defined for its class.

private validateObject(object $object, string $propertyPath, array<string|int, mixed> $groups, int $traversalStrategy, ExecutionContextInterface $context) : mixed

If no metadata is available for the class, but the class is an instance of and the selected traversal strategy allows traversal, the object will be iterated and each nested object will be validated instead.

Parameters
$object : object
$propertyPath : string
$groups : array<string|int, mixed>
$traversalStrategy : int
$context : ExecutionContextInterface
Tags
throws
NoSuchMetadataException

If the object has no associated metadata and does not implement or if traversal is disabled via the $traversalStrategy argument

throws
UnsupportedMetadataException

If the metadata returned by the metadata factory does not implement


        
On this page

Search results