src/Security/Authorization/Voter/DashboardVoter.php line 9

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Security\Authorization\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.     public const SUBJECT 'servicedesk.dashboard';
  9.     public const READ 'servicedesk.dashboard.read';
  10.     public const WRITE 'servicedesk.dashboard.write';
  11.     protected function supports(string $attribute$subject): bool
  12.     {
  13.         return in_array($attribute, [self::READself::WRITE]) && $subject === self::SUBJECT;
  14.     }
  15.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  16.     {
  17.         $user $token->getUser();
  18.         if (!$user instanceof UserInterface) {
  19.             return false;
  20.         }
  21.         return in_array($attribute$user->getRoles());
  22.     }
  23. }