src/Security/Voter/ElearningPlatform/InsiderAccessVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\ElearningPlatform;
  3. use App\Entity\User;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. /**
  7.  * @extends Voter<string, mixed>
  8.  */
  9. class InsiderAccessVoter extends Voter
  10. {
  11.     public const INSIDER_ACCESS 'insider_access';
  12.     public const ANONYMOUS_USER 'anon.';
  13.     protected function supports(string $attribute$subject): bool
  14.     {
  15.         return self::INSIDER_ACCESS === $attribute;
  16.     }
  17.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  18.     {
  19.         /** @var User|null $user */
  20.         $user $token->getUser();
  21.         if (null === $user) {
  22.             return false;
  23.         }
  24.         if (self::ANONYMOUS_USER === (string) $user) {
  25.             return false;
  26.         }
  27.         $member $user->getMember();
  28.         if (null === $member) {
  29.             return false;
  30.         }
  31.         if (true === $member->isDeleted()) {
  32.             return false;
  33.         }
  34.         return $member->isInsider();
  35.     }
  36. }