<?php
namespace App\Security\Voter;
use App\Entity\MasterForm;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class MasterFormVoter extends Voter
{
public const PREVIEW = 'MASTER_FORM_PREVIEW';
/**
* @param string $attribute
* @param $subject
* @return bool
*/
protected function supports(string $attribute, $subject): bool
{
return $attribute == self::PREVIEW && $subject instanceof MasterForm;
}
/**
* @param string $attribute
* @param $subject
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
if ($attribute == self::PREVIEW) {
return $this->canPreview($subject);
}
return false;
}
/**
* @param MasterForm $form
* @return bool
*/
private function canPreview(MasterForm $form): bool
{
return $form->isActive();
}
}