register birthdateValidator

in birthdate validator, improve the message
This commit is contained in:
2015-12-10 14:55:12 +01:00
parent 71eb972c4c
commit 04c56f667a
8 changed files with 58 additions and 7 deletions

View File

@@ -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';
}
}

View File

@@ -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();
}