<?php
namespace App\Security\Voter;
use App\Entity\InvoiceStatus;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class InvoiceStatusVoter extends Voter
{
protected function supports($attribute, $subject): bool
{
$supportsAttribute = in_array($attribute, ['edit', 'delete']);
$supportsSubject = $subject instanceof InvoiceStatus;
return $supportsAttribute && $supportsSubject;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$authenticatedUser = $token->getUser();
if (!$authenticatedUser instanceof User) return false;
/** @var InvoiceStatus $invoiceStatus */
$invoiceStatus = $subject;
return $invoiceStatus->isCanDelete();
}
}