src/Security/Voter/MessageContentVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\MessageContent;
  4. use App\Entity\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. use Symfony\Component\Security\Core\Security;
  8. class MessageContentVoter extends Voter
  9. {
  10.     const DELETE 'delete';
  11.     private $security;
  12.     public function __construct(Security $security)
  13.     {
  14.         $this->security $security;
  15.     }
  16.     protected function supports($attribute$subject)
  17.     {
  18.         if (!in_array($attribute, [self::DELETE])) {
  19.             return false;
  20.         }
  21.         if (!$subject instanceof MessageContent) {
  22.             return false;
  23.         }
  24.         return true;
  25.     }
  26.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  27.     {
  28.         $user $token->getUser();
  29.         if (!$user instanceof User) {
  30.             return false;
  31.         }
  32.         /** @var MessageContent $messageContent */
  33.         $messageContent $subject;
  34.         switch ($attribute) {
  35.             case self::DELETE:
  36.                 return $this->canDelete($messageContent$user$token);
  37.         }
  38.         throw new \LogicException('This code should not be reached!');
  39.     }
  40.     private function canDelete(MessageContent $messageContentUser $userTokenInterface $token)
  41.     {
  42.         return false;
  43.     }
  44. }