vendor/nellapp/sdk-bundle/src/Permission/Security/Voter/SuperAdminVoter.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the nellapp-core package.
  4.  *
  5.  * (c) Benjamin Georgeault
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Nellapp\Bundle\SDKBundle\Permission\Security\Voter;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. /**
  15.  * GRANT access to everything for Super Admin only.
  16.  *
  17.  * @author Benjamin Georgeault
  18.  */
  19. class SuperAdminVoter implements VoterInterface
  20. {
  21.     public function vote(TokenInterface $token$subject, array $attributes): int
  22.     {
  23.         if (null === $subject) {
  24.             return VoterInterface::ACCESS_ABSTAIN;
  25.         }
  26.         $user $token->getUser();
  27.         if ($user instanceof UserInterface) {
  28.             if (in_array('ROLE_SUPER_ADMIN'$user->getRoles())) {
  29.                 return VoterInterface::ACCESS_GRANTED;
  30.             }
  31.         }
  32.         return VoterInterface::ACCESS_ABSTAIN;
  33.     }
  34. }