src/Security/Voter/LiteraturePdfVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter;
  4. use App\Entity\Literature\Literature;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. class LiteraturePdfVoter extends Voter
  9. {
  10.     public const SHOW_LITERATURE_NVC_PDF 'SHOW_LITERATURE_NVC_PDF';
  11.     private AuthorizationCheckerInterface $authorizationChecker;
  12.     /**
  13.      * ReportPdfVoter constructor.
  14.      */
  15.     public function __construct(AuthorizationCheckerInterface $authorizationChecker)
  16.     {
  17.         $this->authorizationChecker $authorizationChecker;
  18.     }
  19.     protected function supports(string $attribute$subject)
  20.     {
  21.         if (!$subject instanceof Literature) {
  22.             return false;
  23.         }
  24.         return in_array($attribute, [
  25.             self::SHOW_LITERATURE_NVC_PDF,
  26.         ]);
  27.     }
  28.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token)
  29.     {
  30.         assert($subject instanceof Literature);
  31.         return $this->authorizationChecker->isGranted('ROLE_NVC');
  32.     }
  33. }