<?php
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class SuperAdminVoter extends Voter
{
/**
* {@inheritDoc}
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
// if $attribute is ROLE_PREVIOUS_ADMIN, ABSTAIN
if ('ROLE_PREVIOUS_ADMIN' === $attribute) {
return self::ACCESS_ABSTAIN;
}
if (\in_array('ROLE_SUPER_ADMIN', $token->getRoleNames(), true)) {
return true;
}
return self::ACCESS_ABSTAIN;
}
/**
* {@inheritDoc}
*/
protected function supports($attribute, $subject): bool
{
return true;
}
}