mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 01:53:49 +00:00
register birthdateValidator
in birthdate validator, improve the message
This commit is contained in:
@@ -34,4 +34,9 @@ use Symfony\Component\Validator\Constraint;
|
||||
class Birthdate extends Constraint
|
||||
{
|
||||
public $message = "The birthdate must be before %date%";
|
||||
|
||||
public function validatedBy()
|
||||
{
|
||||
return 'birthdate_not_before';
|
||||
}
|
||||
}
|
||||
|
@@ -38,6 +38,11 @@ class BirthdateValidator extends ConstraintValidator
|
||||
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if ($value === NULL) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$value instanceof \DateTime) {
|
||||
throw new \LogicException('The input should a be a \DateTime interface,'
|
||||
. (is_object($value) ? get_class($value) : gettype($value)));
|
||||
@@ -47,7 +52,7 @@ class BirthdateValidator extends ConstraintValidator
|
||||
|
||||
if ($limitDate < $value) {
|
||||
$this->context->buildViolation($constraint->message)
|
||||
->setParameter('%date%', $value->format(\DateTime::ATOM))
|
||||
->setParameter('%date%', $limitDate->format('d-m-Y'))
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user