You are here

public function Validator::validatePropertyValue in Zircon Profile 8

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

Throws

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

Overrides ValidatorInterface::validatePropertyValue

File

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

Class

Validator
Default implementation of {@link ValidatorInterface}.

Namespace

Symfony\Component\Validator

Code

public function validatePropertyValue($containingValue, $property, $value, $groups = null) {
  $visitor = $this
    ->createVisitor(is_object($containingValue) ? $containingValue : $value);
  $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 ' . $valueAsString . ' does not support properties.'));
  }

  // If $containingValue is passed as class name, take $value as root
  // and start the traversal with an empty property path
  $propertyPath = is_object($containingValue) ? $property : '';
  foreach ($this
    ->resolveGroups($groups) as $group) {
    if (!$metadata
      ->hasPropertyMetadata($property)) {
      continue;
    }
    foreach ($metadata
      ->getPropertyMetadata($property) as $propMeta) {
      $propMeta
        ->accept($visitor, $value, $group, $propertyPath);
    }
  }
  return $visitor
    ->getViolations();
}