You are here

public function Validator::validateProperty in Zircon Profile 8

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

Throws

ValidatorException If the metadata for the value does not support properties.

Overrides ValidatorInterface::validateProperty

File

vendor/symfony/validator/Validator.php, line 113

Class

Validator
Default implementation of {@link ValidatorInterface}.

Namespace

Symfony\Component\Validator

Code

public function validateProperty($containingValue, $property, $groups = null) {
  $visitor = $this
    ->createVisitor($containingValue);
  $metadata = $this->metadataFactory
    ->getMetadataFor($containingValue);
  if (!$metadata instanceof PropertyMetadataContainerInterface) {
    $valueAsString = is_scalar($containingValue) ? '"' . $containingValue . '"' : 'the value of type ' . gettype($containingValue);
    throw new ValidatorException(sprintf('The metadata for %s does not support properties.', $valueAsString));
  }
  foreach ($this
    ->resolveGroups($groups) as $group) {
    if (!$metadata
      ->hasPropertyMetadata($property)) {
      continue;
    }
    foreach ($metadata
      ->getPropertyMetadata($property) as $propMeta) {
      $propMeta
        ->accept($visitor, $propMeta
        ->getPropertyValue($containingValue), $group, $property);
    }
  }
  return $visitor
    ->getViolations();
}