configuration = $configuration; $this->repository = $repository; } /** * @param TimesheetEntity $timesheet * @param Constraint $constraint */ public function validate($timesheet, Constraint $constraint) { if (!($constraint instanceof TimesheetOverlapping)) { throw new UnexpectedTypeException($constraint, TimesheetOverlapping::class); } if (!\is_object($timesheet) || !($timesheet instanceof TimesheetEntity)) { throw new UnexpectedTypeException($timesheet, TimesheetEntity::class); } if ($this->configuration->isAllowOverlappingRecords()) { return; } if (!$this->repository->hasRecordForTime($timesheet)) { return; } $this->context->buildViolation('You already have an entry for this time.') ->atPath('begin') ->setTranslationDomain('validators') ->setCode(TimesheetOverlapping::RECORD_OVERLAPPING) ->addViolation(); } }