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

Open in your IDE?
  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. private $roleHierarchy;
  22. public function __construct(RoleHierarchyInterface $roleHierarchy, string $prefix = 'ROLE_')
  23. {
  24. $this->roleHierarchy = $roleHierarchy;
  25. parent::__construct($prefix);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function extractRoles(TokenInterface $token)
  31. {
  32. return $this->roleHierarchy->getReachableRoleNames($token->getRoleNames());
  33. }
  34. }