src/Voter/__Accounting/AccountingSellingVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Voter\__Accounting;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. class AccountingSellingVoter extends Voter
  7. {
  8.     const COMPANY_SALE_LIST "ACCOUNTING_SELLING_COMPANY_SALE_LIST";
  9.     const COMPANY_SALE_SHOW_ALL_SELLERS "ACCOUNTING_SELLING_COMPANY_SALE_SHOW_ALL_SELLERS";
  10.     const PARTNER_SALE_LIST "ACCOUNTING_SELLING_PARTNER_SALE_LIST";
  11.     const PARTNER_SALE_SHOW_ALL_SELLERS "ACCOUNTING_SELLING_PARTNER_SALE_SHOW_ALL_SELLERS";
  12.     const SELLER_SALE_LIST "ACCOUNTING_SELLING_SELLER_SALE_LIST";
  13.     const SELLER_SALE_SHOW_ALL_SELLERS "ACCOUNTING_SELLING_SELLER_SALE_SHOW_ALL_SELLERS";
  14.     const CABIN_SALE_LIST "ACCOUNTING_SELLING_CABIN_SALE_LIST";
  15.     const CABIN_SALE_SHOW_ALL_SELLERS "ACCOUNTING_SELLING_CABIN_SALE_SHOW_ALL_SELLERS";
  16.     protected function supports($attribute$subject): bool
  17.     {
  18.         return in_array($attribute, [
  19.             self::COMPANY_SALE_LIST,
  20.             self::COMPANY_SALE_SHOW_ALL_SELLERS,
  21.             self::PARTNER_SALE_LIST,
  22.             self::PARTNER_SALE_SHOW_ALL_SELLERS,
  23.             self::SELLER_SALE_LIST,
  24.             self::SELLER_SALE_SHOW_ALL_SELLERS,
  25.             self::CABIN_SALE_LIST,
  26.             self::CABIN_SALE_SHOW_ALL_SELLERS,
  27.         ]);
  28.     }
  29.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  30.     {
  31.         $loggedUser $token->getUser();
  32.         if (!$loggedUser instanceof UserInterface) {
  33.             return false;
  34.         }
  35.         return in_array($attribute$loggedUser->getRoles());
  36.     }
  37. }