<?php
declare(strict_types=1);
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ExactRoleVoter extends Voter
{
protected function supports(string $attribute, mixed $subject): bool
{
return str_starts_with($attribute, 'ROLE_EXACT_');
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$role = 'ROLE_' . substr($attribute, \strlen('ROLE_EXACT_'));
$roles = $token->getRoleNames();
return \in_array($role, $roles, true);
}
}