class RecursiveValidator
Same name in other branches
- 8.9.x core/lib/Drupal/Core/TypedData/Validation/RecursiveValidator.php \Drupal\Core\TypedData\Validation\RecursiveValidator
- 10 core/lib/Drupal/Core/TypedData/Validation/RecursiveValidator.php \Drupal\Core\TypedData\Validation\RecursiveValidator
- 11.x core/lib/Drupal/Core/TypedData/Validation/RecursiveValidator.php \Drupal\Core\TypedData\Validation\RecursiveValidator
Defines a recursive validator for Typed Data.
The difference to \Symfony\Component\Validator\Validator\RecursiveValidator is that we just allow to validate typed data objects.
Hierarchy
- class \Drupal\Core\TypedData\Validation\RecursiveValidator implements \Symfony\Component\Validator\Validator\ValidatorInterface
Expanded class hierarchy of RecursiveValidator
2 files declare their use of RecursiveValidator
- RecursiveContextualValidatorTest.php in core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php - TypedDataManager.php in core/
lib/ Drupal/ Core/ TypedData/ TypedDataManager.php
File
-
core/
lib/ Drupal/ Core/ TypedData/ Validation/ RecursiveValidator.php, line 21
Namespace
Drupal\Core\TypedData\ValidationView source
class RecursiveValidator implements ValidatorInterface {
/**
* @var \Symfony\Component\Validator\Context\ExecutionContextFactoryInterface
*/
protected $contextFactory;
/**
* @var \Symfony\Component\Validator\ConstraintValidatorFactoryInterface
*/
protected $constraintValidatorFactory;
/**
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedDataManager;
/**
* Creates a new validator.
*
* @param \Symfony\Component\Validator\Context\ExecutionContextFactoryInterface $context_factory
* The factory for creating new contexts.
* @param \Symfony\Component\Validator\ConstraintValidatorFactoryInterface $validator_factory
* The constraint validator factory.
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
* The typed data manager.
*/
public function __construct(ExecutionContextFactoryInterface $context_factory, ConstraintValidatorFactoryInterface $validator_factory, TypedDataManagerInterface $typed_data_manager) {
$this->contextFactory = $context_factory;
$this->constraintValidatorFactory = $validator_factory;
$this->typedDataManager = $typed_data_manager;
}
/**
* {@inheritdoc}
*/
public function startContext($root = NULL) : ContextualValidatorInterface {
return new RecursiveContextualValidator($this->contextFactory
->createContext($this, $root), $this, $this->constraintValidatorFactory, $this->typedDataManager);
}
/**
* {@inheritdoc}
*/
public function inContext(ExecutionContextInterface $context) : ContextualValidatorInterface {
return new RecursiveContextualValidator($context, $this, $this->constraintValidatorFactory, $this->typedDataManager);
}
/**
* {@inheritdoc}
*
* @param \Drupal\Core\TypedData\TypedDataInterface $typed_data
* A typed data object containing the value to validate.
*/
public function getMetadataFor($typed_data) : MetadataInterface {
if (!$typed_data instanceof TypedDataInterface) {
throw new \InvalidArgumentException('The passed value must be a typed data object.');
}
return new TypedDataMetadata($typed_data);
}
/**
* {@inheritdoc}
*/
public function hasMetadataFor($value) : bool {
return $value instanceof TypedDataInterface;
}
/**
* {@inheritdoc}
*/
public function validate($value, $constraints = NULL, $groups = NULL) : ConstraintViolationListInterface {
return $this->startContext($value)
->validate($value, $constraints, $groups)
->getViolations();
}
/**
* {@inheritdoc}
*/
public function validateProperty($object, $propertyName, $groups = NULL) : ConstraintViolationListInterface {
return $this->startContext($object)
->validateProperty($object, $propertyName, $groups)
->getViolations();
}
/**
* {@inheritdoc}
*/
public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = NULL) : ConstraintViolationListInterface {
// Just passing a class name is not supported.
if (!is_object($objectOrClass)) {
throw new \LogicException('Typed data validation does not support passing the class name only.');
}
return $this->startContext($objectOrClass)
->validatePropertyValue($objectOrClass, $propertyName, $value, $groups)
->getViolations();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RecursiveValidator::$constraintValidatorFactory | protected | property | |
RecursiveValidator::$contextFactory | protected | property | |
RecursiveValidator::$typedDataManager | protected | property | |
RecursiveValidator::getMetadataFor | public | function | |
RecursiveValidator::hasMetadataFor | public | function | |
RecursiveValidator::inContext | public | function | |
RecursiveValidator::startContext | public | function | |
RecursiveValidator::validate | public | function | |
RecursiveValidator::validateProperty | public | function | |
RecursiveValidator::validatePropertyValue | public | function | |
RecursiveValidator::__construct | public | function | Creates a new validator. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.