<?php
namespace App\V4\Voters;
use App\Security\SecurityConfig;
use App\Security\User;
use LogicException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class TagVoter extends Voter
{
public const TAG_USE = 'tag_use';
protected function supports($attribute, $subject): bool
{
return $attribute === self::TAG_USE;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
if ($attribute === self::TAG_USE) {
return in_array(SecurityConfig::MODULE_TAG, $user->getRoles(), true);
}
throw new LogicException('This should never happen');
}
}