src/Voter/DashboardVoter.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 DashboardVoter extends Voter
  7. {
  8.     const LIST = "DASHBOARD_LIST";
  9.     protected function supports($attribute$subject): bool
  10.     {
  11.         return in_array($attribute, [
  12.             self::LIST,
  13.         ]);
  14.     }
  15.     
  16.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  17.     {
  18.         $loggedUser $token->getUser();
  19.         if (!$loggedUser instanceof UserInterface) {
  20.             return false;
  21.         }
  22.         return in_array($attribute$loggedUser->getRoles());
  23.     }
  24. }