src/Security/Voter/NielsenOrderVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\NielsenOrder;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. class NielsenOrderVoter extends AbstractVoter
  6. {
  7.     public const LIST = 'NielsenOrder:ViewList';
  8.     private ?NielsenOrder $nielsenOrder null;
  9.     protected function supports(string $attributemixed $subject): bool
  10.     {
  11.         return $attribute === self::LIST;
  12.     }
  13.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  14.     {
  15.         $this->user $token->getUser();
  16.         $this->nielsenOrder $subject;
  17.         return match ($attribute) {
  18.             self::LIST => $this->canViewList(),
  19.             default => false,
  20.         };
  21.     }
  22.     private function canViewList(): bool
  23.     {
  24.         // Read-only superadmins can view Nielsen orders
  25.         return $this->isSuperAdmin() || $this->isReadOnlySuperAdmin();
  26.     }
  27. }