src/Bidcoz/Bundle/CoreBundle/Security/Authorization/Voter/UserVoter.php line 14

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
  3. use Bidcoz\Bundle\CoreBundle\Entity\User as AppUser;
  4. use RS\DiExtraBundle\Annotation as DI;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. /**
  8.  * @DI\Service
  9.  * @DI\Tag("security.voter")
  10.  */
  11. class UserVoter extends Voter
  12. {
  13.     const USER_ENABLED 'USER_ENABLED';
  14.     protected function supports(string $attribute$subject): bool
  15.     {
  16.         return $attribute === self::USER_ENABLED;
  17.     }
  18.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  19.     {
  20.         $user $token->getUser();
  21.         if (!$user instanceof AppUser) {
  22.             return true;
  23.         }
  24.         return $user->isEnabled();
  25.     }
  26. }