<?php
namespace App\Security\Voter;
use App\Entity\Eg\Admin\Role;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* ROLE_SUPER_ADMIN jako rola techniczna: daje wszystko, bez wypisywania ponad stu ról w role_hierarchy.
*/
final class SuperAdminVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
return \str_starts_with($attribute, 'ROLE_')
|| \in_array($attribute, self::customAttributes(), true);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return \in_array(Role::ROLE_SUPER_ADMIN, $token->getRoleNames(), true);
}
/**
* @return string[]
*/
private static function customAttributes(): array
{
return \array_merge(
FineVoter::ATTRIBUTES,
RequestLogVoter::ATTRIBUTES,
UserVoter::ATTRIBUTES,
UserGroupVoter::ATTRIBUTES
);
}
}