You are here

public function RecursiveContextualValidator::validatePropertyValue in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/validator/Validator/RecursiveContextualValidator.php \Symfony\Component\Validator\Validator\RecursiveContextualValidator::validatePropertyValue()
  2. 8 core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php \Drupal\Core\TypedData\Validation\RecursiveContextualValidator::validatePropertyValue()
Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Validator/RecursiveContextualValidator.php \Symfony\Component\Validator\Validator\RecursiveContextualValidator::validatePropertyValue()

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

Parameters

object|string $objectOrClass The object or its class name:

string $propertyName The name of the property:

mixed $value The value to validate against the: property's constraints

array|null $groups The validation groups to validate. If: none is given, "Default" is assumed

Return value

ContextualValidatorInterface This validator

Overrides ContextualValidatorInterface::validatePropertyValue

File

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

Class

RecursiveContextualValidator
Recursive implementation of {@link ContextualValidatorInterface}.

Namespace

Symfony\Component\Validator\Validator

Code

public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null) {
  $classMetadata = $this->metadataFactory
    ->getMetadataFor($objectOrClass);
  if (!$classMetadata instanceof ClassMetadataInterface) {

    // Cannot be UnsupportedMetadataException because of BC with
    // Symfony < 2.5
    throw new ValidatorException(sprintf('The metadata factory should return instances of ' . '"\\Symfony\\Component\\Validator\\Mapping\\ClassMetadataInterface", ' . 'got: "%s".', is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)));
  }
  $propertyMetadatas = $classMetadata
    ->getPropertyMetadata($propertyName);
  $groups = $groups ? $this
    ->normalizeGroups($groups) : $this->defaultGroups;
  if (is_object($objectOrClass)) {
    $object = $objectOrClass;
    $cacheKey = spl_object_hash($objectOrClass);
    $propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
  }
  else {

    // $objectOrClass contains a class name
    $object = null;
    $cacheKey = null;
    $propertyPath = $this->defaultPropertyPath;
  }
  $previousValue = $this->context
    ->getValue();
  $previousObject = $this->context
    ->getObject();
  $previousMetadata = $this->context
    ->getMetadata();
  $previousPath = $this->context
    ->getPropertyPath();
  $previousGroup = $this->context
    ->getGroup();
  foreach ($propertyMetadatas as $propertyMetadata) {
    $this
      ->validateGenericNode($value, $object, $cacheKey . ':' . $propertyName, $propertyMetadata, $propertyPath, $groups, null, TraversalStrategy::IMPLICIT, $this->context);
  }
  $this->context
    ->setNode($previousValue, $previousObject, $previousMetadata, $previousPath);
  $this->context
    ->setGroup($previousGroup);
  return $this;
}