<?php
namespace FlexApp\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class RoleSuperAdminVoter extends _ExtendVoter
{
protected array $methods = [];
protected function supports(string $attribute, $subject): bool
{
//return $this->checkMethods($attribute);
// здесь отдаем стразу TRUE
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
// проверяем на роль ROLE_SUPER_ADMIN
$user = $token->getUser();
if ($user instanceof UserInterface) {
// PREVIOUS_ADMIN проверяем отдельно от SUPER_ADMIN
if ($attribute == 'ROLE_PREVIOUS_ADMIN') {
if (in_array('ROLE_PREVIOUS_ADMIN', $user->getRoles())) {
return true;
}
} else {
if (in_array('ROLE_SUPER_ADMIN', $user->getRoles())) {
return true;
}
}
}
return false;
}
}