<?php
declare(strict_types=1);
namespace App\Security\Voter;
use App\Service\CommentaryService;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class CuratorCommentaryHWRVoter extends Voter
{
public const CURATOR_SEE_HWR = 'CURATOR_SEE_HWR';
private CommentaryService $commentaryService;
public function __construct(CommentaryService $commentaryService)
{
$this->commentaryService = $commentaryService;
}
protected function supports($attribute, $commentaryId): bool
{
return $attribute === self::CURATOR_SEE_HWR
&& is_int($commentaryId);
}
protected function voteOnAttribute($attribute, $commentaryId, TokenInterface $token): bool
{
return $this->commentaryService->handleCuratorCommentaryAccess($commentaryId, $token->getUser());
}
}