class WhenValidator
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
- class \Symfony\Component\Validator\Constraints\WhenValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of WhenValidator
File
-
vendor/
symfony/ validator/ Constraints/ WhenValidator.php, line 20
Namespace
Symfony\Component\Validator\ConstraintsView source
final class WhenValidator extends ConstraintValidator {
public function __construct(?ExpressionLanguage $expressionLanguage = null) {
}
public function validate(mixed $value, Constraint $constraint) : void {
if (!$constraint instanceof When) {
throw new UnexpectedTypeException($constraint, When::class);
}
$context = $this->context;
$variables = $constraint->values;
$variables['value'] = $value;
$variables['this'] = $context->getObject();
$variables['context'] = $context;
if ($this->getExpressionLanguage()
->evaluate($constraint->expression, $variables)) {
$context->getValidator()
->inContext($context)
->validate($value, $constraint->constraints);
}
}
private function getExpressionLanguage() : ExpressionLanguage {
if (!class_exists(ExpressionLanguage::class)) {
throw new LogicException(\sprintf('The "symfony/expression-language" component is required to use the "%s" validator. Try running "composer require symfony/expression-language".', __CLASS__));
}
return $this->expressionLanguage ??= new ExpressionLanguage();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ConstraintValidator::$context | protected | property | ||
ConstraintValidator::formatTypeOf | protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator::formatValue | protected | function | Returns a string representation of the value. | |
ConstraintValidator::formatValues | protected | function | Returns a string representation of a list of values. | |
ConstraintValidator::initialize | public | function | Initializes the constraint validator. | Overrides ConstraintValidatorInterface::initialize |
ConstraintValidator::OBJECT_TO_STRING | public | constant | Whether to cast objects with a "__toString()" method to strings. | |
ConstraintValidator::PRETTY_DATE | public | constant | Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s"). |
|
WhenValidator::getExpressionLanguage | private | function | ||
WhenValidator::validate | public | function | Checks if the passed value is valid. | Overrides ConstraintValidatorInterface::validate |
WhenValidator::__construct | public | function |