<?php
namespace App\Legacy\Voter\User;
use App\Legacy\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class SwitchToUserVoter extends Voter
{
protected function supports($attribute, $subject)
{
return in_array($attribute, ['CAMBIAR_USUARIO']);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return $user->isAdmin();
}
}