You are here

private function RecursiveContextualValidator::validateEachObjectIn in Plug 7

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

If the parameter $recursive is set to true, nested {@link \Traversable} objects are iterated as well. Nested arrays are always iterated, regardless of the value of $recursive.

Parameters

array|\Traversable $collection The collection:

string $propertyPath The current property path:

string[] $groups The validated groups:

bool $stopRecursion Whether to disable: recursive iteration. For backwards compatibility with Symfony < 2.5.

ExecutionContextInterface $context The current execution context:

See also

ClassNode

CollectionNode

4 calls to RecursiveContextualValidator::validateEachObjectIn()
RecursiveContextualValidator::validate in lib/Symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
Validates a value against a constraint or a list of constraints.
RecursiveContextualValidator::validateClassNode in lib/Symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
Validates a class node.
RecursiveContextualValidator::validateGenericNode in lib/Symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
Validates a node that is not a class node.
RecursiveContextualValidator::validateObject in lib/Symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
Validates an object against the constraints defined for its class.

File

lib/Symfony/validator/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php, line 397

Class

RecursiveContextualValidator
Recursive implementation of {@link ContextualValidatorInterface}.

Namespace

Symfony\Component\Validator\Validator

Code

private function validateEachObjectIn($collection, $propertyPath, array $groups, $stopRecursion, ExecutionContextInterface $context) {
  if ($stopRecursion) {
    $traversalStrategy = TraversalStrategy::NONE;
  }
  else {
    $traversalStrategy = TraversalStrategy::IMPLICIT;
  }
  foreach ($collection as $key => $value) {
    if (is_array($value)) {

      // Arrays are always cascaded, independent of the specified
      // traversal strategy
      // (BC with Symfony < 2.5)
      $this
        ->validateEachObjectIn($value, $propertyPath . '[' . $key . ']', $groups, $stopRecursion, $context);
      continue;
    }

    // Scalar and null values in the collection are ignored
    // (BC with Symfony < 2.5)
    if (is_object($value)) {
      $this
        ->validateObject($value, $propertyPath . '[' . $key . ']', $groups, $traversalStrategy, $context);
    }
  }
}