src/Security/Voter/FrontUserVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\FrontUser;
  4. use App\Utils\VoterHelper;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class FrontUserVoter extends Voter
  8. {
  9.     private const EDIT           'edit';
  10.     private const CREATE         'create';
  11.     private const DELETE         'delete';
  12.     private const RESET_PASSWORD 'reset-password';
  13.     private const SWITCH_STATUS  'switch-status';
  14.     private const IMPERSONATE    'impersonate';
  15.     /**
  16.      * UserVoter constructor.
  17.      */
  18.     public function __construct()
  19.     {
  20.     }
  21.     protected function supports(string $attributemixed $subject): bool
  22.     {
  23.         return $subject instanceof FrontUser && in_array($attribute, [self::EDITself::CREATEself::DELETEself::RESET_PASSWORDself::SWITCH_STATUSself::IMPERSONATE], true);
  24.     }
  25.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  26.     {
  27.         switch ($attribute) {
  28.             case self::IMPERSONATE:
  29.                 if (!$subject->getEnabled()) {
  30.                     return false;
  31.                 }
  32.                 break;
  33.         }
  34.         return VoterHelper::voteOnAttribute($attribute$subject$token'front_user');
  35.     }
  36. }