vendor/nen/questionnaire-bundle/src/Security/Voter/UserRespondentVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace Nen\Bundle\QuestionnaireBundle\Security\Voter;
  3. use App\Entity\User;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  7. class UserRespondentVoter extends Voter
  8. {
  9.     protected function supports(string $attribute$subject): bool
  10.     {
  11.         return $subject instanceof User && $subject->hasRespondent();
  12.     }
  13.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  14.     {
  15.         /** @var User $user */
  16.         $user $subject;
  17.         if ($attribute !== 'remove') {
  18.             return VoterInterface::ACCESS_ABSTAIN;
  19.         }
  20.         return $user->getRespondent()->getQuestionnaires()->count() === 0;
  21.     }
  22. }