src/User/Voter/DeleteUserVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\User\Voter;
  4. use Harmonizely\Model\User;
  5. use Harmonizely\Model\UserInterface;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. final class DeleteUserVoter extends Voter
  9. {
  10.     /**
  11.      * @deprecated don't use this method
  12.      * */
  13.     public const DELETE_USER 'delete_user';
  14.     protected function supports($attribute$subject): bool
  15.     {
  16.         if (self::DELETE_USER !== $attribute) {
  17.             return false;
  18.         }
  19.         if (false === $subject instanceof UserInterface) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24.     /**
  25.      * @deprecated don't use this method
  26.      * @param $attribute
  27.      * @param $subject
  28.      * @param TokenInterface $token
  29.      * @return bool
  30.      */
  31.     protected function voteOnAttribute($attribute$subjectTokenInterface $token): bool
  32.     {
  33.         /** @var User $subject */
  34.         /** @var UserInterface $loggedInUser */
  35.         $loggedInUser $token->getUser();
  36.         return $loggedInUser->getId() === $subject->getId();
  37.     }
  38. }