<?php
namespace App\Security\Authorization\Voter;
use App\Entity\User;
use App\Entity\Vehicle;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class EditVehicleVoter extends Voter
{
public const EDIT = 'edit';
public function __construct(private readonly AccessDecisionManagerInterface $decisionManager)
{
}
protected function supports($attribute, $subject)
{
if (self::EDIT !== $attribute) {
return false;
}
if (!$subject instanceof Vehicle) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return $this->decisionManager->decide($token, ['ROLE_SALESPERSON'])
|| $this->decisionManager->decide($token, ['ROLE_LIVE_OPERATOR'])
|| $this->decisionManager->decide($token, ['ROLE_LIVE_AUCTIONEER']);
}
}