Command
1 year ago
Constraints
1 year ago
Context
1 year ago
Exception
3 years ago
Mapping
3 months ago
Util
3 years ago
Validator
6 months ago
Violation
3 years ago
Constraint.php
1 year ago
ConstraintValidator.php
1 year ago
ConstraintValidatorFactory.php
4 years ago
ConstraintValidatorFactoryInterface.php
4 years ago
ConstraintValidatorInterface.php
4 years ago
ConstraintViolation.php
1 year ago
ConstraintViolationInterface.php
4 years ago
ConstraintViolationList.php
4 years ago
ConstraintViolationListInterface.php
4 years ago
ContainerConstraintValidatorFactory.php
4 years ago
GroupSequenceProviderInterface.php
4 years ago
ObjectInitializerInterface.php
4 years ago
Validation.php
4 years ago
ValidatorBuilder.php
4 years ago
index.php
3 years ago
Validation.php
45 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Exception\ValidationFailedException; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Validator\ValidatorInterface; |
| 6 | final class Validation |
| 7 | { |
| 8 | public static function createCallable($constraintOrValidator = null, Constraint ...$constraints) : callable |
| 9 | { |
| 10 | $validator = self::createIsValidCallable($constraintOrValidator, ...$constraints); |
| 11 | return static function ($value) use($validator) { |
| 12 | if (!$validator($value, $violations)) { |
| 13 | throw new ValidationFailedException($value, $violations); |
| 14 | } |
| 15 | return $value; |
| 16 | }; |
| 17 | } |
| 18 | public static function createIsValidCallable($constraintOrValidator = null, Constraint ...$constraints) : callable |
| 19 | { |
| 20 | $validator = $constraintOrValidator; |
| 21 | if ($constraintOrValidator instanceof Constraint) { |
| 22 | $constraints = \func_get_args(); |
| 23 | $validator = null; |
| 24 | } elseif (null !== $constraintOrValidator && !$constraintOrValidator instanceof ValidatorInterface) { |
| 25 | throw new \TypeError(\sprintf('Argument 1 passed to "%s()" must be a "%s" or a "%s" object, "%s" given.', __METHOD__, Constraint::class, ValidatorInterface::class, \get_debug_type($constraintOrValidator))); |
| 26 | } |
| 27 | $validator = $validator ?? self::createValidator(); |
| 28 | return static function ($value, &$violations = null) use($constraints, $validator) { |
| 29 | $violations = $validator->validate($value, $constraints); |
| 30 | return 0 === $violations->count(); |
| 31 | }; |
| 32 | } |
| 33 | public static function createValidator() : ValidatorInterface |
| 34 | { |
| 35 | return self::createValidatorBuilder()->getValidator(); |
| 36 | } |
| 37 | public static function createValidatorBuilder() : ValidatorBuilder |
| 38 | { |
| 39 | return new ValidatorBuilder(); |
| 40 | } |
| 41 | private function __construct() |
| 42 | { |
| 43 | } |
| 44 | } |
| 45 |