<?php
declare(strict_types=1);
namespace Harmonizely\User\Voter;
use Harmonizely\Model\User;
use Harmonizely\Model\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
final class DeleteUserVoter extends Voter
{
/**
* @deprecated don't use this method
* */
public const DELETE_USER = 'delete_user';
protected function supports($attribute, $subject): bool
{
if (self::DELETE_USER !== $attribute) {
return false;
}
if (false === $subject instanceof UserInterface) {
return false;
}
return true;
}
/**
* @deprecated don't use this method
* @param $attribute
* @param $subject
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
/** @var User $subject */
/** @var UserInterface $loggedInUser */
$loggedInUser = $token->getUser();
return $loggedInUser->getId() === $subject->getId();
}
}