src/Security/Voter/BoardVoter.php line 10
<?phpnamespace App\Security\Voter;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Security\Core\Security;class BoardVoter extends Voter{private $security;public function __construct(Security $security){$this->security = $security;}public const EDIT = 'BOARD_EDIT';public const VIEW = 'BOARD_DELETE';public const LIST = 'BOARD_LIST';protected function supports(string $attribute, $subject): bool{// replace with your own logic// https://symfony.com/doc/current/security/voters.htmlreturn in_array($attribute, [self::EDIT, self::VIEW, self::LIST])&& $subject instanceof \App\Entity\Board;}protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool{if ($this->security->isGranted('ROLE_ADMIN')) {return true;}$user = $token->getUser();// if the user is anonymous, do not grant accessif (!$user instanceof UserInterface) {//return false;}// ... (check conditions and return true to grant permission) ...switch ($attribute) {case self::EDIT:// logic to determine if the user can EDIT// return true or falsebreak;case self::VIEW:// logic to determine if the user can VIEW// return true or falsebreak;case self::LIST:// logic to determine if the user can VIEW// return true or falsebreak;}return false;}}