<?php
declare(strict_types=1);
namespace App\Security\Voter;
use App\Entity\Show;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
class ShowVoter extends Voter
{
/** @required */
public Security $securityChecker;
protected function supports(string $attribute, $subject): bool
{
return $attribute === 'SHOW_ENABLED' && $subject instanceof Show;
}
/**
* @param string $attribute
* @param Show $subject
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
if ($this->securityChecker->isGranted('ROLE_SHOW_READ')) {
return true;
}
return $subject->isEnabled();
}
}