You are here

public function RecursiveContextualValidator::validateProperty in Zircon Profile 8

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

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

Parameters

object $object The object:

string $propertyName The name of the validated property:

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

Return value

ContextualValidatorInterface This validator

Overrides ContextualValidatorInterface::validateProperty

File

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

Class

RecursiveContextualValidator
Recursive implementation of {@link ContextualValidatorInterface}.

Namespace

Symfony\Component\Validator\Validator

Code

public function validateProperty($object, $propertyName, $groups = null) {
  $classMetadata = $this->metadataFactory
    ->getMetadataFor($object);
  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;
  $cacheKey = spl_object_hash($object);
  $propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
  $previousValue = $this->context
    ->getValue();
  $previousObject = $this->context
    ->getObject();
  $previousMetadata = $this->context
    ->getMetadata();
  $previousPath = $this->context
    ->getPropertyPath();
  $previousGroup = $this->context
    ->getGroup();
  foreach ($propertyMetadatas as $propertyMetadata) {
    $propertyValue = $propertyMetadata
      ->getPropertyValue($object);
    $this
      ->validateGenericNode($propertyValue, $object, $cacheKey . ':' . $propertyName, $propertyMetadata, $propertyPath, $groups, null, TraversalStrategy::IMPLICIT, $this->context);
  }
  $this->context
    ->setNode($previousValue, $previousObject, $previousMetadata, $previousPath);
  $this->context
    ->setGroup($previousGroup);
  return $this;
}