<?php
namespace App\Security;
use App\Entity\User\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
class AdminSogecVoter extends Voter
{
const ADMIN_SOGEC_VOTER_VIEW = 'admin_sogec_voter_view';
const ADMIN_SOGEC_VOTER_EDIT = 'admin_sogec_voter_edit';
const ADMIN_SOGEC_VOTER_DELETE = 'admin_sogec_voter_delete';
const ADMIN_SOGEC_VOTER_NEW = 'admin_sogec_voter_new';
const ARRAY_ADMIN_SOGEC_VOTER = [
self::ADMIN_SOGEC_VOTER_VIEW,
self::ADMIN_SOGEC_VOTER_EDIT,
self::ADMIN_SOGEC_VOTER_DELETE,
self::ADMIN_SOGEC_VOTER_NEW,
];
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
protected function supports($attribute, $subject): bool
{
if (!in_array($attribute, self::ARRAY_ADMIN_SOGEC_VOTER)) {
return false;
}
if (!$subject instanceof User) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if ($this->security->isGranted(User::ROLE_ADMIN_SOGEC)) {
return true;
}
return false;
}
}