src/Voter/BookingVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Voter;
  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 BookingVoter extends Voter
  7. {
  8.     const LIST = "BOOKING_LIST";
  9.     const CREATE "BOOKING_CREATE";
  10.     const UPDATE "BOOKING_UPDATE";
  11.     const DETAIL "BOOKING_DETAIL";
  12.     const CONTRACT_LIST "BOOKING_CONTRACT_LIST";
  13.     const FULL_WEB_LIST "BOOKING_FULL_WEB_LIST";
  14.     const SHOW_ALL_SELLERS "BOOKING_SHOW_ALL_SELLERS";
  15.     protected function supports($attribute$subject): bool
  16.     {
  17.         return in_array($attribute, [
  18.             self::LIST,
  19.             self::CREATE,
  20.             self::UPDATE,
  21.             self::DETAIL,
  22.             self::CONTRACT_LIST,
  23.             self::FULL_WEB_LIST,
  24.             self::SHOW_ALL_SELLERS,
  25.         ]);
  26.     }
  27.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  28.     {
  29.         $loggedUser $token->getUser();
  30.         if (!$loggedUser instanceof UserInterface) {
  31.             return false;
  32.         }
  33.         return in_array($attribute$loggedUser->getRoles());
  34.     }
  35. }