src/Voter/__Accounting/AccountingRefundVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Voter\__Accounting;
  3. use App\Voter\VoterTrait;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. class AccountingRefundVoter extends Voter
  8. {
  9.     use VoterTrait;
  10.     const LIST = "ACCOUNTING_REFUND_LIST";
  11.     protected function supports($attribute$subject): bool
  12.     {
  13.         return ($attribute == self::LIST && $subject === null);
  14.     }
  15.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  16.     {
  17.         $loggedUser $token->getUser();
  18.         if (!$loggedUser instanceof UserInterface) {
  19.             return false;
  20.         }
  21.         switch ($attribute) {
  22.             case self::LIST:
  23.                 return $this->voteOnList($loggedUser);
  24.         }
  25.         return false;
  26.     }
  27.     private function voteOnList(UserInterface $loggedUser): bool
  28.     {
  29.         return in_array(self::LIST, $loggedUser->getRoles());
  30.     }
  31. }