src/Security/Voter/ShowVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter;
  4. use App\Entity\Show;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. use Symfony\Component\Security\Core\Security;
  8. class ShowVoter extends Voter
  9. {
  10.     /** @required */
  11.     public Security $securityChecker;
  12.     protected function supports(string $attribute$subject): bool
  13.     {
  14.         return $attribute === 'SHOW_ENABLED' && $subject instanceof Show;
  15.     }
  16.     /**
  17.      * @param string $attribute
  18.      * @param Show $subject
  19.      * @param TokenInterface $token
  20.      * @return bool
  21.      */
  22.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  23.     {
  24.         if ($this->securityChecker->isGranted('ROLE_SHOW_READ')) {
  25.             return true;
  26.         }
  27.         return $subject->isEnabled();
  28.     }
  29. }