src/StartPlatz/Bundle/ToolBundle/Security/SystemAccessVoter.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\ToolBundle\Security;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. class SystemAccessVoter extends Voter
  6. {
  7.     public const TOOL_ACCESS 'TOOL_ACCESS';
  8.     public const PERSONNEL_ACCESS 'PERSONNEL_ACCESS';
  9.     public const PERSONNEL_HOLDING 'PERSONNEL_HOLDING';
  10.     protected function supports(string $attribute$subject): bool
  11.     {
  12.         return in_array($attribute, [self::TOOL_ACCESSself::PERSONNEL_ACCESSself::PERSONNEL_HOLDING], true) && $subject === null;
  13.     }
  14.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  15.     {
  16.         $user $token->getUser();
  17.         if (!$user || !method_exists($user'getMemberId')) {
  18.             return false;
  19.         }
  20.         $memberId $user->getMemberId();
  21.         if ($memberId === null) {
  22.             return false;
  23.         }
  24.         if ($attribute === self::PERSONNEL_HOLDING) {
  25.             return SystemAccessProvider::isPersonnelHolding($memberId);
  26.         }
  27.         if ($attribute === self::PERSONNEL_ACCESS) {
  28.             return SystemAccessProvider::isPersonnelAuthorized($memberId);
  29.         }
  30.         return SystemAccessProvider::isAuthorized($memberId);
  31.     }
  32. }