src/Security/TeamVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. namespace App\Security;
  4. use App\Entity\Team;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class TeamVoter extends Voter
  8. {
  9.     protected function supports(string $attribute$subject): bool
  10.     {
  11.         if ($attribute === 'VIEW_TEAMS') {
  12.             return true;
  13.         }
  14.         
  15.         return $subject instanceof Team && $attribute === 'VIEW';
  16.     }
  17.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  18.     {
  19.         $user $token->getUser();
  20.         
  21.         if (!$user) {
  22.             return false;
  23.         }
  24.         
  25.         if ($attribute === 'VIEW_TEAMS') {
  26.             return true;
  27.         }
  28.         
  29.         if ($subject instanceof Team) {
  30.            return true;
  31.         }
  32.         
  33.         return false;
  34.     }
  35. }