public function Validator::validatePropertyValue in Plug 7
Throws
ValidatorException If the metadata for the value does not support properties.
Overrides ValidatorInterface::validatePropertyValue
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ Validator.php, line 142
Class
- Validator
- Default implementation of {@link ValidatorInterface}.
Namespace
Symfony\Component\ValidatorCode
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();
}