<?php
namespace App\Security\Authorization\Voter\ServiceDesk;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class TicketVoter extends Voter
{
public const SUBJECT = 'servicedesk.ticket';
public const READ = 'servicedesk.ticket.read';
public const WRITE = 'servicedesk.ticket.write';
protected function supports(string $attribute, $subject): bool
{
return in_array($attribute, [self::READ, self::WRITE]) && $subject === self::SUBJECT;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
return in_array($attribute, $user->getRoles());
}
}