src/V4/Voters/TagVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\V4\Voters;
  3. use App\Security\SecurityConfig;
  4. use App\Security\User;
  5. use LogicException;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class TagVoter extends Voter
  9. {
  10.     public const TAG_USE 'tag_use';
  11.     protected function supports($attribute$subject): bool
  12.     {
  13.         return $attribute === self::TAG_USE;
  14.     }
  15.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  16.     {
  17.         $user $token->getUser();
  18.         if (!$user instanceof User) {
  19.             return false;
  20.         }
  21.         if ($attribute === self::TAG_USE) {
  22.             return in_array(SecurityConfig::MODULE_TAG$user->getRoles(), true);
  23.         }
  24.         throw new LogicException('This should never happen');
  25.     }
  26. }