vendor/symfony/security-core/Authorization/Voter/RoleHierarchyVoter.php line 23

  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Core\Authorization\Voter;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
  13. /**
  14. * RoleHierarchyVoter uses a RoleHierarchy to determine the roles granted to
  15. * the user before voting.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class RoleHierarchyVoter extends RoleVoter
  20. {
  21. public function __construct(
  22. private RoleHierarchyInterface $roleHierarchy,
  23. string $prefix = 'ROLE_',
  24. ) {
  25. parent::__construct($prefix);
  26. }
  27. protected function extractRoles(TokenInterface $token): array
  28. {
  29. return $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
  30. }
  31. }