src/Security/Voter/SuperAdminVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\Eg\Admin\Role;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. /**
  7.  * ROLE_SUPER_ADMIN jako rola techniczna: daje wszystko, bez wypisywania ponad stu ról w role_hierarchy.
  8.  */
  9. final class SuperAdminVoter extends Voter
  10. {
  11.     protected function supports(string $attribute, $subject): bool
  12.     {
  13.         return \str_starts_with($attribute, 'ROLE_')
  14.             || \in_array($attribute, self::customAttributes(), true);
  15.     }
  16.     protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
  17.     {
  18.         return \in_array(Role::ROLE_SUPER_ADMIN, $token->getRoleNames(), true);
  19.     }
  20.     /**
  21.      * @return string[]
  22.      */
  23.     private static function customAttributes(): array
  24.     {
  25.         return \array_merge(
  26.             FineVoter::ATTRIBUTES,
  27.             RequestLogVoter::ATTRIBUTES,
  28.             UserVoter::ATTRIBUTES,
  29.             UserGroupVoter::ATTRIBUTES
  30.         );
  31.     }
  32. }