<?php
declare(strict_types=1);
namespace App\Security\Voter;
use App\Entity\Literature\Literature;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class LiteraturePdfVoter extends Voter
{
public const SHOW_LITERATURE_NVC_PDF = 'SHOW_LITERATURE_NVC_PDF';
private AuthorizationCheckerInterface $authorizationChecker;
/**
* ReportPdfVoter constructor.
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
protected function supports(string $attribute, $subject)
{
if (!$subject instanceof Literature) {
return false;
}
return in_array($attribute, [
self::SHOW_LITERATURE_NVC_PDF,
]);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
{
assert($subject instanceof Literature);
return $this->authorizationChecker->isGranted('ROLE_NVC');
}
}