src/Security/Voter/RealizationsPageVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Security\Voter;
  4. use App\Entity\StaticPages\RealizationsPage;
  5. use App\Entity\User\AdminUser;
  6. use App\Repository\RealizationsPageRepository;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. class RealizationsPageVoter extends Voter
  10. {
  11.     const CAN_VIEW_REALIZATION_PAGE 'CAN_VIEW_REALIZATION_PAGE';
  12.     private $realizationsPageRepository;
  13.     public function __construct(RealizationsPageRepository $realizationsPageRepository)
  14.     {
  15.         $this->realizationsPageRepository $realizationsPageRepository;
  16.     }
  17.     protected function supports(string $attribute$subject)
  18.     {
  19.         return $attribute == self::CAN_VIEW_REALIZATION_PAGE;
  20.     }
  21.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token)
  22.     {
  23.         $user $token->getUser();
  24.         $realizationPageState $this->realizationsPageRepository->findSingleInstance()->getState();
  25.         if (!$user instanceof AdminUser) {
  26.             return $realizationPageState !== RealizationsPage::STATE_DRAFT;
  27.         }
  28.     }
  29. }