RoleHierarchyVoter

class RoleHierarchyVoter extends RoleVoter

RoleHierarchyVoter uses a RoleHierarchy to determine the roles granted to the user before voting.

Methods

__construct(RoleHierarchyInterface $roleHierarchy, string $prefix = 'ROLE_')

Constructor.

bool supportsAttribute(string $attribute)

Checks if the voter supports the given attribute.

from RoleVoter
bool supportsClass(string $class)

Checks if the voter supports the given class.

from RoleVoter
int vote(TokenInterface $token, object|null $object, array $attributes)

Returns the vote for the given parameters.

from RoleVoter

Details

__construct(RoleHierarchyInterface $roleHierarchy, string $prefix = 'ROLE_')

Constructor.

Parameters

RoleHierarchyInterface $roleHierarchy
string $prefix The role prefix

bool supportsAttribute(string $attribute)

Checks if the voter supports the given attribute.

Parameters

string $attribute An attribute

Return Value

bool true if this Voter supports the attribute, false otherwise

bool supportsClass(string $class)

Checks if the voter supports the given class.

Parameters

string $class A class name

Return Value

bool true if this Voter can process the class

int vote(TokenInterface $token, object|null $object, array $attributes)

Returns the vote for the given parameters.

This method must return one of the following constants: ACCESSGRANTED, ACCESSDENIED, or ACCESS_ABSTAIN.

Parameters

TokenInterface $token A TokenInterface instance
object|null $object The object to secure
array $attributes An array of attributes associated with the method being invoked

Return Value

int either ACCESSGRANTED, ACCESSABSTAIN, or ACCESS_DENIED