src/AppBundle/Security/WamVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Security;
  3. use AppBundle\Entity\User;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. class WamVoter extends Voter
  7. {
  8.     public const IS_WAM_USER 'IS_WAM_USER';
  9.     public const IS_NOT_WAM_USER 'IS_NOT_WAM_USER';
  10.     protected function supports($attribute$subject)
  11.     {
  12.         return in_array($attribute, [self::IS_WAM_USERself::IS_NOT_WAM_USER], true);
  13.     }
  14.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  15.     {
  16.         $user $token->getUser();
  17.         if (!$user instanceof User) {
  18.             return false;
  19.         }
  20.         $isWamUser = (null !== $user->getLawFirm()?->getEcmId());
  21.         if (self::IS_WAM_USER === $attribute) {
  22.             return $isWamUser;
  23.         }
  24.         return !$isWamUser;
  25.     }
  26. }