mediatekformation

RecursiveContextualValidator
in package
implements ContextualValidatorInterface

Recursive implementation of {@link ContextualValidatorInterface}.

Tags
author

Bernhard Schussek bschussek@gmail.com

Interfaces, Classes, Traits and Enums

ContextualValidatorInterface
A validator in a specific execution context.

Table of Contents

$context  : mixed
$defaultGroups  : mixed
$defaultPropertyPath  : mixed
$metadataFactory  : mixed
$objectInitializers  : mixed
$validatorFactory  : mixed
__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|\Symfony\Component\Validator\Constraints\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

Return values
mixed

atPath()

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

public atPath(mixed $path) : $this
Parameters
$path : mixed

The path to append

Return values
$this

validate()

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

public validate(mixed $value[, mixed $constraints = null ][, mixed $groups = null ]) : $this
Parameters
$value : mixed

The value to validate

$constraints : mixed = null

The constraint(s) to validate against

$groups : 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(mixed $object, mixed $propertyName[, mixed $groups = null ]) : $this
Parameters
$object : mixed

The object

$propertyName : mixed

The name of the validated property

$groups : 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(mixed $objectOrClass, mixed $propertyName, mixed $value[, mixed $groups = null ]) : $this
Parameters
$objectOrClass : mixed

The object or its class name

$propertyName : mixed

The name of the property

$value : mixed

The value to validate against the property's constraints

$groups : mixed = null

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

Return values
$this

normalizeGroups()

Normalizes the given group or list of groups to an array.

protected normalizeGroups(string|GroupSequence|array<string|int, string|\Symfony\Component\Validator\Constraints\GroupSequence> $groups) : array<string|int, string|\Symfony\Component\Validator\Constraints\GroupSequence>
Parameters
$groups : string|GroupSequence|array<string|int, string|\Symfony\Component\Validator\Constraints\GroupSequence>

The groups to normalize

Return values
array<string|int, string|\Symfony\Component\Validator\Constraints\GroupSequence>

A group array

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

The validated value

$object : object|null

The current object

$cacheKey : string|null
$metadata : MetadataInterface|null
$propertyPath : string
$traversalStrategy : int
$groupSequence : GroupSequence
$cascadedGroup : string|null
$context : ExecutionContextInterface
Return values
mixed

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 (conceptionally) 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

The validated 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
Return values
mixed

validateEachObjectIn()

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

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

Nested arrays are also iterated.

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

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

The validated value

$object : object|null

The current object

$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
Return values
mixed

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

The object to cascade

$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

Return values
mixed

Search results