voterHelper = $voterHelperFactory ->generate(self::class) ->addCheckFor(PersonDocument::class, $this->getRoles()) ->addCheckFor(Person::class, [self::SEE, self::CREATE]) ->build(); } public function getRoles(): array { return [ self::CREATE, self::SEE, self::SEE_DETAILS, self::UPDATE, self::DELETE, ]; } public function getRolesWithHierarchy(): array { return ['PersonDocument' => $this->getRoles()]; } public function getRolesWithoutScope(): array { return []; } protected function supports($attribute, $subject) { return $this->voterHelper->supports($attribute, $subject); } /** * @param string $attribute * @param PersonDocument $subject * * @return bool */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { $this->logger->debug(sprintf('Voting from %s class', self::class)); if (!$token->getUser() instanceof User) { return false; } if ( $subject instanceof PersonDocument && !$this->security->isGranted(PersonVoter::SEE, $subject->getPerson()) ) { return false; } return $this->voterHelper->voteOnAttribute($attribute, $subject, $token); } }