class Validation
Entry point for the Validator component.
@author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Validation
Expanded class hierarchy of Validation
5 files declare their use of Validation
- CompoundConstraintTestCase.php in vendor/
symfony/ validator/ Test/ CompoundConstraintTestCase.php - Context.php in core/
lib/ Drupal/ Component/ Plugin/ Context/ Context.php - ProjectRelease.php in core/
modules/ update/ src/ ProjectRelease.php - Recipe.php in core/
lib/ Drupal/ Core/ Recipe/ Recipe.php - SecurityAdvisory.php in core/
modules/ system/ src/ SecurityAdvisories/ SecurityAdvisory.php
File
-
vendor/
symfony/ validator/ Validation.php, line 22
Namespace
Symfony\Component\ValidatorView source
final class Validation {
/**
* Creates a callable chain of constraints.
*/
public static function createCallable(Constraint|ValidatorInterface|null $constraintOrValidator = null, Constraint ...$constraints) : callable {
$validator = self::createIsValidCallable($constraintOrValidator, ...$constraints);
return static function ($value) use ($validator) {
if (!$validator($value, $violations)) {
throw new ValidationFailedException($value, $violations);
}
return $value;
};
}
/**
* Creates a callable that returns true/false instead of throwing validation exceptions.
*
* @return callable(mixed $value, ?ConstraintViolationListInterface &$violations = null): bool
*/
public static function createIsValidCallable(Constraint|ValidatorInterface|null $constraintOrValidator = null, Constraint ...$constraints) : callable {
$validator = $constraintOrValidator;
if ($constraintOrValidator instanceof Constraint) {
$constraints = \func_get_args();
$validator = null;
}
$validator ??= self::createValidator();
return static function (mixed $value, ?ConstraintViolationListInterface &$violations = null) use ($constraints, $validator) : bool {
$violations = $validator->validate($value, $constraints);
return 0 === $violations->count();
};
}
/**
* Creates a new validator.
*
* If you want to configure the validator, use
* {@link createValidatorBuilder()} instead.
*/
public static function createValidator() : ValidatorInterface {
return self::createValidatorBuilder()->getValidator();
}
/**
* Creates a configurable builder for validator objects.
*/
public static function createValidatorBuilder() : ValidatorBuilder {
return new ValidatorBuilder();
}
/**
* This class cannot be instantiated.
*/
private function __construct() {
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Validation::createCallable | public static | function | Creates a callable chain of constraints. |
Validation::createIsValidCallable | public static | function | Creates a callable that returns true/false instead of throwing validation exceptions. |
Validation::createValidator | public static | function | Creates a new validator. |
Validation::createValidatorBuilder | public static | function | Creates a configurable builder for validator objects. |
Validation::__construct | private | function | This class cannot be instantiated. |