interval_spec = $this->parameterBag->get('chill_person')['validation']['birthdate_not_after']; } public function validate($value, Constraint $constraint) { if (null === $value) { return; } if (!$value instanceof DateTime) { throw new LogicException('The input should a be a \DateTime interface,' . (get_debug_type($value))); } if (!$constraint instanceof Birthdate) { throw new UnexpectedTypeException($constraint, Birthdate::class); } $limitDate = $this->getLimitDate(); if ($value > $limitDate) { $this->context->buildViolation($constraint->message) ->setParameter('%date%', $limitDate->format('d-m-Y')) ->setCode(Birthdate::BIRTHDATE_INVALID_CODE) ->addViolation(); } if ($value < $this->getBelowLimitDate()) { $this->context->buildViolation($constraint->belowMessage) ->setParameter('%date%', $this->getBelowLimitDate()->format('d-m-Y')) ->setCode(Birthdate::BIRTHDATE_INVALID_CODE) ->addViolation(); } } private function getLimitDate(): DateTime { $interval = new DateInterval($this->interval_spec); return DateTime::createFromImmutable($this->clock->now()->sub($interval)); } private function getBelowLimitDate(): DateTime { return DateTime::createFromImmutable($this->clock->now()->sub(new DateInterval($this->below_interval))); } }