src/Security/GameVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use App\Model\Operation\Game;
  4. use App\Model\User\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class GameVoter extends Voter
  8. {
  9.     public const GET_GAME 'get_game';
  10.     public const ARRAY_GAME_VOTER = [
  11.         self::GET_GAME,
  12.     ];
  13.     protected function supports($attribute$subject)
  14.     {
  15.         return in_array($attributeself::ARRAY_GAME_VOTER);
  16.     }
  17.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  18.     {
  19.         $boolean false;
  20.         $user $token->getUser();
  21.         if (self::GET_GAME === $attribute) {
  22.             $boolean $this->checkOneGame($user$subject);
  23.         }
  24.         return $boolean;
  25.     }
  26.     protected function checkOneGame($user$subject): bool
  27.     {
  28.         if (!$subject instanceof Game) {
  29.             return false;
  30.         }
  31.         if ($subject->isRequireUser() === true && (!$user instanceof User)) {
  32.             return false;
  33.         }
  34.         return true;
  35.     }
  36. }