You are here

private function RecursiveContextualValidator::validateObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Validator/RecursiveContextualValidator.php \Symfony\Component\Validator\Validator\RecursiveContextualValidator::validateObject()

Validates an object against the constraints defined for its class.

If no metadata is available for the class, but the class is an instance of {@link \Traversable} 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:

string $propertyPath The current property path:

string[] $groups The validated groups:

int $traversalStrategy The strategy for traversing the: cascaded object

ExecutionContextInterface $context The current execution context:

Throws

NoSuchMetadataException If the object has no associated metadata and does not implement {@link \Traversable} or if traversal is disabled via the $traversalStrategy argument

UnsupportedMetadataException If the metadata returned by the metadata factory does not implement {@link ClassMetadataInterface}

3 calls to RecursiveContextualValidator::validateObject()
RecursiveContextualValidator::validate in vendor/symfony/validator/Validator/RecursiveContextualValidator.php
Validates a value against a constraint or a list of constraints.
RecursiveContextualValidator::validateEachObjectIn in vendor/symfony/validator/Validator/RecursiveContextualValidator.php
Validates each object in a collection against the constraints defined for their classes.
RecursiveContextualValidator::validateGenericNode in vendor/symfony/validator/Validator/RecursiveContextualValidator.php
Validates a node that is not a class node.

File

vendor/symfony/validator/Validator/RecursiveContextualValidator.php, line 342

Class

RecursiveContextualValidator
Recursive implementation of {@link ContextualValidatorInterface}.

Namespace

Symfony\Component\Validator\Validator

Code

private function validateObject($object, $propertyPath, array $groups, $traversalStrategy, ExecutionContextInterface $context) {
  try {
    $classMetadata = $this->metadataFactory
      ->getMetadataFor($object);
    if (!$classMetadata instanceof ClassMetadataInterface) {
      throw new UnsupportedMetadataException(sprintf('The metadata factory should return instances of ' . '"Symfony\\Component\\Validator\\Mapping\\ClassMetadataInterface", ' . 'got: "%s".', is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)));
    }
    $this
      ->validateClassNode($object, spl_object_hash($object), $classMetadata, $propertyPath, $groups, null, $traversalStrategy, $context);
  } catch (NoSuchMetadataException $e) {

    // Rethrow if not Traversable
    if (!$object instanceof \Traversable) {
      throw $e;
    }

    // Rethrow unless IMPLICIT or TRAVERSE
    if (!($traversalStrategy & (TraversalStrategy::IMPLICIT | TraversalStrategy::TRAVERSE))) {
      throw $e;
    }
    $this
      ->validateEachObjectIn($object, $propertyPath, $groups, $traversalStrategy & TraversalStrategy::STOP_RECURSION, $context);
  }
}