<?php
namespace App\Security\Voter;
use App\Entity\Channel\Export\FileExport;
use App\Service\Export\FileExportService;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class FileExportVoter extends Voter
{
public const CHANNEL_USER_PERM_EXPORT = 'CHANNEL_USER_PERM_EXPORT';
public function __construct(
private FileExportService $fileExportService,
) {}
protected function supports(string $attribute, $subject): bool
{
return $subject instanceof FileExport && $attribute === self::CHANNEL_USER_PERM_EXPORT;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return $this->fileExportService->hasPerm($subject);
}
}