src/Security/Voter/EventInputOptionVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\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. use Symfony\Component\Security\Core\Security;
  7. class EventInputOptionVoter extends Voter
  8. {
  9.     public const EDIT 'POST_EDIT';
  10.     public const VIEW 'POST_VIEW';
  11.     public const ADD 'POST_ADD';
  12.     public const DELETE 'POST_DELETE';
  13.     public function __construct( private readonly Security $security ) {}
  14.     protected function supports(string $attribute$subject): bool
  15.     {
  16.         return in_array($attribute, [self::EDITself::VIEWself::ADDself::DELETE]);
  17.     }
  18.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  19.     {
  20.         return $this->security->isGranted('ROLE_ADMIN');
  21.     }
  22. }