<?php
namespace App\Security\Voter;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class DisclaimerVoter extends Voter
{
protected function supports($attribute, $subject)
{
return in_array($attribute, [ 'DISCLAIMER_AGREED']);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
// ... (check conditions and return true to grant permission) ...
switch ($attribute) {
case 'DISCLAIMER_AGREED':
if($user->getIsDisclaimer() == true) {
return true;
}
break;
}
return false;
}
}