<?php
namespace App\Security\Voter;
use App\Interface\Handler\Configuration\GetDomainDataInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class RoleVoter extends Voter
{
public function __construct( )
{
}
protected function supports(string $attribute, mixed $subject): bool
{
// Define qué atributos soporta este votante
return in_array($attribute, ['ROL_EMPLOYEE_LIST_THEM_SELF','ROL_EMPLOYEE_ABSENCE_CANCEL']);
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
return in_array($attribute, $user->getRoles());
}
}