diff --git a/src/Symfony/Component/Validator/Validation.php b/src/Symfony/Component/Validator/Validation.php index a070242e60de0..ca80c0597a7e0 100644 --- a/src/Symfony/Component/Validator/Validation.php +++ b/src/Symfony/Component/Validator/Validation.php @@ -23,10 +23,21 @@ final class Validation { /** * Creates a callable chain of constraints. + * + * @param Constraint|ValidatorInterface|null $constraintOrValidator */ - public static function createCallable(Constraint ...$constraints): callable + public static function createCallable($constraintOrValidator = null, Constraint ...$constraints): callable { - $validator = self::createValidator(); + $validator = $constraintOrValidator; + + if ($constraintOrValidator instanceof Constraint) { + $constraints = \func_get_args(); + $validator = null; + } elseif (null !== $constraintOrValidator && !$constraintOrValidator instanceof ValidatorInterface) { + 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))); + } + + $validator = $validator ?? self::createValidator(); return static function ($value) use ($constraints, $validator) { $violations = $validator->validate($value, $constraints);