You are here

public function RecursiveContextualValidator::validateProperty in Plug 7

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

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

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;
}