src/Security/Voter/SuperAdminVoter.php line 8

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. class SuperAdminVoter extends Voter
  6. {
  7.     /**
  8.      * {@inheritDoc}
  9.      */
  10.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  11.     {
  12.         // if $attribute is ROLE_PREVIOUS_ADMIN, ABSTAIN
  13.         if ('ROLE_PREVIOUS_ADMIN' === $attribute) {
  14.             return self::ACCESS_ABSTAIN;
  15.         }
  16.         if (\in_array('ROLE_SUPER_ADMIN'$token->getRoleNames(), true)) {
  17.             return true;
  18.         }
  19.         return self::ACCESS_ABSTAIN;
  20.     }
  21.     /**
  22.      * {@inheritDoc}
  23.      */
  24.     protected function supports($attribute$subject): bool
  25.     {
  26.         return true;
  27.     }
  28. }