<?php
namespace App\Security;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class AdminVoter extends Voter
{
const GET_SOGEC_ADMIN = 'GET_SOGEC_ADMIN';
protected function supports($attribute, $user)
{
return $user instanceof User && $attribute === self::GET_SOGEC_ADMIN;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
switch ($attribute) {
case self::GET_SOGEC_ADMIN:
return $this->checkSogecAdmin($subject);
}
return false;
}
private function checkSogecAdmin(User $user )
{
return $user->hasRole('ROLE_SUPER_ADMIN');
}
}