src/Security/Voter/Notification/NotificationVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\Notification;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. class NotificationVoter extends Voter
  7. {
  8.     public const VIEW 'NOTIFICATION_VIEW';
  9.     protected function supports(string $attributemixed $subject): bool
  10.     {
  11.         return in_array($attribute, [self::VIEW])
  12.             && $subject instanceof \App\Entity\Notification\Notification;
  13.     }
  14.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  15.     {
  16.         $user $token->getUser();
  17.         if (!$user instanceof UserInterface) {
  18.             return false;
  19.         }
  20.         
  21.         switch ($attribute) {
  22.             case self::VIEW:
  23.                 return $subject->getCustomerCompany()->getId() == $user->getCustomerCompany()->getId();
  24.                 break;
  25.         }
  26.         return false;
  27.     }
  28. }