Skip to content
PHP Ecosystem
Explore

ManagerInterface

API reference › yii › rbac › ManagerInterface

interfaceyii\rbac\ManagerInterface
ExtendsCheckAccessInterface
Since2.0
Sourceframework/rbac/ManagerInterface.php
Implemented by 1 type

For more details and usage information on ManagerInterface, see the guide article on security authorization.

MethodDescriptionDefined by
add() abstractAdds a role, permission or rule to the RBAC system.ManagerInterface
addChild() abstractAdds an item as a child of another item.ManagerInterface
assign() abstractAssigns a role to a user.ManagerInterface
canAddChild() abstractChecks the possibility of adding a child to parent.ManagerInterface
checkAccess() abstractChecks if the user has the specified permission.CheckAccessInterface
createPermission() abstractCreates a new Permission object.ManagerInterface
createRole() abstractCreates a new Role object.ManagerInterface
getAssignment() abstractReturns the assignment information regarding a role and a user.ManagerInterface
getAssignments() abstractReturns all role assignment information for the specified user.ManagerInterface
getChildren() abstractReturns the child permissions and/or roles.ManagerInterface
getChildRoles() abstractReturns child roles of the role specified. Depth isn’t limited.ManagerInterface
getPermission() abstractReturns the named permission.ManagerInterface
getPermissions() abstractReturns all permissions in the system.ManagerInterface
getPermissionsByRole() abstractReturns all permissions that the specified role represents.ManagerInterface
getPermissionsByUser() abstractReturns all permissions that the user has.ManagerInterface
getRole() abstractReturns the named role.ManagerInterface
getRoles() abstractReturns all roles in the system.ManagerInterface
getRolesByUser() abstractReturns the roles that are assigned to the user via assign().ManagerInterface
getRule() abstractReturns the rule of the specified name.ManagerInterface
getRules() abstractReturns all rules available in the system.ManagerInterface
getUserIdsByRole() abstractReturns all user IDs assigned to the role specified.ManagerInterface
hasChild() abstractReturns a value indicating whether the child already exists for the parent.ManagerInterface
remove() abstractRemoves a role, permission or rule from the RBAC system.ManagerInterface
removeAll() abstractRemoves all authorization data, including roles, permissions, rules, and assignments.ManagerInterface
removeAllAssignments() abstractRemoves all role assignments.ManagerInterface
removeAllPermissions() abstractRemoves all permissions.ManagerInterface
removeAllRoles() abstractRemoves all roles.ManagerInterface
removeAllRules() abstractRemoves all rules.ManagerInterface
removeChild() abstractRemoves a child from its parent.ManagerInterface
removeChildren() abstractRemoved all children form their parent.ManagerInterface
revoke() abstractRevokes a role from a user.ManagerInterface
revokeAll() abstractRevokes all roles from a user.ManagerInterface
update() abstractUpdates the specified role, permission or rule in the system.ManagerInterface
abstract public function add(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool

Adds a role, permission or rule to the RBAC system.

Parameters

ParameterTypeDescription
$objectRole|Permission|Rule

Returns

bool: Whether the role, permission or rule is successfully added to the system

Throws

  • Exception: if data validation or saving fails (such as the name of the role or permission is not unique)
abstract public function addChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool

Adds an item as a child of another item.

Parameters

ParameterTypeDescription
$parentItem
$childItem

Returns

bool: Whether the child successfully added

Throws

  • yii\base\Exception: if the parent-child relationship already exists or if a loop has been detected.
abstract public function assign(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): yii\rbac\Assignment

Assigns a role to a user.

Parameters

ParameterTypeDescription
$roleRole|Permission
$userIdstring|intThe user ID (see User::$id)

Returns

Assignment: The role assignment information.

Throws

  • Exception: if the role has already been assigned to the user
abstract public function canAddChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool

Checks the possibility of adding a child to parent.

Parameters

ParameterTypeDescription
$parentItemThe parent item
$childItemThe child item to be added to the hierarchy

Returns

bool: Possibility of adding

Since

2.0.8

abstract public function createPermission(string $name): yii\rbac\Permission

Creates a new Permission object.

Note that the newly created permission is not added to the RBAC system yet. You must fill in the needed data and call add() to add it to the system.

Parameters

ParameterTypeDescription
$namestringThe permission name

Returns

Permission: The new Permission object

abstract public function createRole(string $name): yii\rbac\Role

Creates a new Role object.

Note that the newly created role is not added to the RBAC system yet. You must fill in the needed data and call add() to add it to the system.

Parameters

ParameterTypeDescription
$namestringThe role name

Returns

Role: The new Role object

abstract public function getAssignment(string $roleName, string|int $userId): yii\rbac\Assignment|null

Returns the assignment information regarding a role and a user.

Parameters

ParameterTypeDescription
$roleNamestringThe role name
$userIdstring|intThe user ID (see User::$id)

Returns

Assignment|null: The assignment information. Null is returned if the role is not assigned to the user.

abstract public function getAssignments(string|int $userId): yii\rbac\Assignment[]

Returns all role assignment information for the specified user.

Parameters

ParameterTypeDescription
$userIdstring|intThe user ID (see User::$id)

Returns

Assignment[]: The assignments indexed by role names. An empty array will be returned if there is no role assigned to the user.

abstract public function getChildren(string $name): yii\rbac\Item[]

Returns the child permissions and/or roles.

Parameters

ParameterTypeDescription
$namestringThe parent name

Returns

Item[]: The child permissions and/or roles

abstract public function getChildRoles(string $roleName): yii\rbac\Role[]

Returns child roles of the role specified. Depth isn’t limited.

Parameters

ParameterTypeDescription
$roleNamestringName of the role to file child roles for

Returns

Role[]: Child roles. The array is indexed by the role names. First element is an instance of the parent Role itself.

Throws

Since

2.0.10

abstract public function getPermission(string $name): yii\rbac\Permission|null

Returns the named permission.

Parameters

ParameterTypeDescription
$namestringThe permission name.

Returns

Permission|null: The permission corresponding to the specified name. Null is returned if no such permission.

abstract public function getPermissions(): yii\rbac\Permission[]

Returns all permissions in the system.

Returns

Permission[]: All permissions in the system. The array is indexed by the permission names.

abstract public function getPermissionsByRole(string $roleName): yii\rbac\Permission[]

Returns all permissions that the specified role represents.

Parameters

ParameterTypeDescription
$roleNamestringThe role name

Returns

Permission[]: All permissions that the role represents. The array is indexed by the permission names.

abstract public function getPermissionsByUser(string|int $userId): yii\rbac\Permission[]

Returns all permissions that the user has.

Parameters

ParameterTypeDescription
$userIdstring|intThe user ID (see User::$id)

Returns

Permission[]: All permissions that the user has. The array is indexed by the permission names.

abstract public function getRole(string $name): yii\rbac\Role|null

Returns the named role.

Parameters

ParameterTypeDescription
$namestringThe role name.

Returns

Role|null: The role corresponding to the specified name. Null is returned if no such role.

abstract public function getRoles(): yii\rbac\Role[]

Returns all roles in the system.

Returns

Role[]: All roles in the system. The array is indexed by the role names.

abstract public function getRolesByUser(string|int $userId): yii\rbac\Role[]

Returns the roles that are assigned to the user via assign().

Note that child roles that are not assigned directly to the user will not be returned.

Parameters

ParameterTypeDescription
$userIdstring|intThe user ID (see User::$id)

Returns

Role[]: All roles directly assigned to the user. The array is indexed by the role names.

abstract public function getRule(string $name): yii\rbac\Rule|null

Returns the rule of the specified name.

Parameters

ParameterTypeDescription
$namestringThe rule name

Returns

Rule|null: The rule object, or null if the specified name does not correspond to a rule.

abstract public function getRules(): yii\rbac\Rule[]

Returns all rules available in the system.

Returns

Rule[]: The rules indexed by the rule names

abstract public function getUserIdsByRole(string $roleName): array

Returns all user IDs assigned to the role specified.

Parameters

ParameterTypeDescription
$roleNamestring

Returns

array: Array of user ID strings

Since

2.0.7

abstract public function hasChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool

Returns a value indicating whether the child already exists for the parent.

Parameters

ParameterTypeDescription
$parentItem
$childItem

Returns

bool: Whether $child is already a child of $parent

abstract public function remove(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool

Removes a role, permission or rule from the RBAC system.

Parameters

ParameterTypeDescription
$objectRole|Permission|Rule

Returns

bool: Whether the role, permission or rule is successfully removed

abstract public function removeAll(): mixed

Removes all authorization data, including roles, permissions, rules, and assignments.

Returns

mixed

abstract public function removeAllAssignments(): mixed

Removes all role assignments.

Returns

mixed

abstract public function removeAllPermissions(): mixed

Removes all permissions.

All parent child relations will be adjusted accordingly.

Returns

mixed

abstract public function removeAllRoles(): mixed

Removes all roles.

All parent child relations will be adjusted accordingly.

Returns

mixed

abstract public function removeAllRules(): mixed

Removes all rules.

All roles and permissions which have rules will be adjusted accordingly.

Returns

mixed

abstract public function removeChild(yii\rbac\Item $parent, yii\rbac\Item $child): bool

Removes a child from its parent.

Note, the child item is not deleted. Only the parent-child relationship is removed.

Parameters

ParameterTypeDescription
$parentItem
$childItem

Returns

bool: Whether the removal is successful

abstract public function removeChildren(yii\rbac\Item $parent): bool

Removed all children form their parent.

Note, the children items are not deleted. Only the parent-child relationships are removed.

Parameters

ParameterTypeDescription
$parentItem

Returns

bool: Whether the removal is successful

abstract public function revoke(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): bool

Revokes a role from a user.

Parameters

ParameterTypeDescription
$roleRole|Permission
$userIdstring|intThe user ID (see User::$id)

Returns

bool: Whether the revoking is successful

abstract public function revokeAll(mixed $userId): bool

Revokes all roles from a user.

Parameters

ParameterTypeDescription
$userIdmixedThe user ID (see User::$id)

Returns

bool: Whether the revoking is successful

abstract public function update(string $name, yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): bool

Updates the specified role, permission or rule in the system.

Parameters

ParameterTypeDescription
$namestringThe old name of the role, permission or rule
$objectRole|Permission|Rule

Returns

bool: Whether the update is successful

Throws

  • Exception: if data validation or saving fails (such as the name of the role or permission is not unique)