vendor/appaydin/pd-user/Security/SuperAdminVoter.php line 24

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the pd-admin pd-user package.
  4.  *
  5.  * @package     pd-user
  6.  * @license     LICENSE
  7.  * @author      Ramazan APAYDIN <apaydin541@gmail.com>
  8.  * @link        https://github.com/appaydin/pd-user
  9.  */
  10. namespace Pd\UserBundle\Security;
  11. use Pd\UserBundle\Model\User;
  12. use Pd\UserBundle\Model\UserInterface;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  14. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  15. /**
  16.  * Super Admin All Access Voter.
  17.  *
  18.  * @author Ramazan APAYDIN <apaydin541@gmail.com>
  19.  */
  20. class SuperAdminVoter extends Voter
  21. {
  22.     protected function supports($attribute$subject): bool
  23.     {
  24.         $excluded = [
  25.             'IS_AUTHENTICATED_ANONYMOUSLY',
  26.             'IS_AUTHENTICATED_FULLY',
  27.             'IS_AUTHENTICATED_REMEMBERED',
  28.             'ISGRANTED_VOTER',
  29.             'ROLE_PREVIOUS_ADMIN',
  30.             'IS_IMPERSONATOR',
  31.         ];
  32.         if (!\is_array($attribute)) {
  33.             $attribute = [$attribute];
  34.         }
  35.         foreach ($attribute as $item) {
  36.             if (\in_array($item$excludedfalse)) {
  37.                 return false;
  38.             }
  39.         }
  40.         return true;
  41.     }
  42.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  43.     {
  44.         // Get User
  45.         $user $token->getUser();
  46.         // Check Login
  47.         if (!$user instanceof UserInterface) {
  48.             return false;
  49.         }
  50.         // Check All Access
  51.         if (\in_array(User::ROLE_ALL_ACCESS$user->getRoles(), true)) {
  52.             return true;
  53.         }
  54.         return false;
  55.     }
  56. }