<?php
namespace App\Security\Voters;
use App\Entity\PriceMap;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ProductVoter extends Voter
{
public const CAN_BE_DELETED = 'product.can_be_deleted';
private const ATTRIBUTES = [
self::CAN_BE_DELETED,
];
protected function supports($attribute, $subject): bool
{
return in_array($attribute, self::ATTRIBUTES);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
switch ($attribute) {
case self::CAN_BE_DELETED:
return $this->canBeDeleted($subject);
}
throw new \LogicException('Invalid attribute: '.$attribute);
}
private function canBeDeleted(PriceMap $product): bool
{
return true;
}
}