<?php
namespace App\Security;
use App\Model\User\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class BlogVoter extends Voter
{
public const GET_BLOG = 'get_blog';
public const ARRAY_BLOG_VOTER = [
self::GET_BLOG,
];
protected function supports($attribute, $subject): bool
{
return in_array($attribute, self::ARRAY_BLOG_VOTER);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if (true == $subject) {
return true;
}
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return true;
}
}