src/Security/Voter/ConversationVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\Conversation;
  4. use App\Repository\ConversationRepository;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. class ConversationVoter extends Voter
  8. {
  9.     /**
  10.      * @var ConversationRepository
  11.      */
  12.     private $conversationRepository;
  13.     public function __construct(ConversationRepository $conversationRepository)
  14.     {
  15.         $this->conversationRepository $conversationRepository;
  16.     }
  17.     const View 'view';
  18.     protected function supports(string $attribute$subject)
  19.     {
  20.         return $attribute == self::View && $subject instanceof Conversation;
  21.     }
  22.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token)
  23.     {
  24.         $result $this->conversationRepository->checkIfUserisParticipant(
  25.             $subject->getId(),
  26.             $token->getUser()->getId()
  27.         );
  28.         return !!$result;
  29.     }
  30. }