src/Security/Voter/ElearningPlatform/DirectorOrMoreAccessVoter.php line 13

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