Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -13,22 +13,42 @@ use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class DateTimeFormatValidator extends ConstraintValidator
final class DateTimeFormatValidator extends ConstraintValidator
{
/**
* @param string|mixed $value
* @param string|mixed|null $value
* @param Constraint $constraint
*/
public function validate($value, Constraint $constraint)
public function validate(mixed $value, Constraint $constraint): void
{
if (!($constraint instanceof DateTimeFormat)) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\DateTimeFormat');
}
if ($value === null) {
if (!\is_string($value)) {
return;
}
if ($constraint->separator === null || $constraint->separator === '') {
if (str_contains($value, ',')) {
$this->context->buildViolation('The given value should not contain a comma.')
->setTranslationDomain('validators')
->setCode(DateTimeFormat::INVALID_FORMAT)
->addViolation();
}
$this->validateDateTime($value);
return;
}
foreach (explode($constraint->separator, $value) as $v) {
$this->validateDateTime($v);
}
}
private function validateDateTime(mixed $value): void
{
$valid = true;
if (!\is_string($value)) {