Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user