personRender = $personRender; $this->thirdpartyRender = $thirdPartyRender; } public function validate($resources, Constraint $constraint) { if (!$constraint instanceof ResourceDuplicateCheck) { throw new UnexpectedTypeException($constraint, ParticipationOverlap::class); } if (!$resources instanceof Collection) { throw new UnexpectedTypeException($resources, Collection::class); } if (0 === count($resources)) { return; } $resourceList = []; foreach ($resources as $resource) { $id = ($resource->getResource() instanceof Person ? 'p' : 't') . $resource->getResource()->getId(); if (in_array($id, $resourceList, true)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ name }}', $resource->getResource() instanceof Person ? $this->personRender->renderString($resource->getResource(), []) : $this->thirdpartyRender->renderString($resource->getResource(), [])) ->addViolation(); } $resourceList[] = $id; } } }