ManagerInterface
API reference › yii › rbac › ManagerInterface
Implemented by 1 type
For more details and usage information on ManagerInterface, see the guide article on security authorization.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
add() abstract | Adds a role, permission or rule to the RBAC system. | ManagerInterface |
addChild() abstract | Adds an item as a child of another item. | ManagerInterface |
assign() abstract | Assigns a role to a user. | ManagerInterface |
canAddChild() abstract | Checks the possibility of adding a child to parent. | ManagerInterface |
checkAccess() abstract | Checks if the user has the specified permission. | CheckAccessInterface |
createPermission() abstract | Creates a new Permission object. | ManagerInterface |
createRole() abstract | Creates a new Role object. | ManagerInterface |
getAssignment() abstract | Returns the assignment information regarding a role and a user. | ManagerInterface |
getAssignments() abstract | Returns all role assignment information for the specified user. | ManagerInterface |
getChildren() abstract | Returns the child permissions and/or roles. | ManagerInterface |
getChildRoles() abstract | Returns child roles of the role specified. Depth isn’t limited. | ManagerInterface |
getPermission() abstract | Returns the named permission. | ManagerInterface |
getPermissions() abstract | Returns all permissions in the system. | ManagerInterface |
getPermissionsByRole() abstract | Returns all permissions that the specified role represents. | ManagerInterface |
getPermissionsByUser() abstract | Returns all permissions that the user has. | ManagerInterface |
getRole() abstract | Returns the named role. | ManagerInterface |
getRoles() abstract | Returns all roles in the system. | ManagerInterface |
getRolesByUser() abstract | Returns the roles that are assigned to the user via assign(). | ManagerInterface |
getRule() abstract | Returns the rule of the specified name. | ManagerInterface |
getRules() abstract | Returns all rules available in the system. | ManagerInterface |
getUserIdsByRole() abstract | Returns all user IDs assigned to the role specified. | ManagerInterface |
hasChild() abstract | Returns a value indicating whether the child already exists for the parent. | ManagerInterface |
remove() abstract | Removes a role, permission or rule from the RBAC system. | ManagerInterface |
removeAll() abstract | Removes all authorization data, including roles, permissions, rules, and assignments. | ManagerInterface |
removeAllAssignments() abstract | Removes all role assignments. | ManagerInterface |
removeAllPermissions() abstract | Removes all permissions. | ManagerInterface |
removeAllRoles() abstract | Removes all roles. | ManagerInterface |
removeAllRules() abstract | Removes all rules. | ManagerInterface |
removeChild() abstract | Removes a child from its parent. | ManagerInterface |
removeChildren() abstract | Removed all children form their parent. | ManagerInterface |
revoke() abstract | Revokes a role from a user. | ManagerInterface |
revokeAll() abstract | Revokes all roles from a user. | ManagerInterface |
update() abstract | Updates the specified role, permission or rule in the system. | ManagerInterface |
Method details
Section titled “Method details”add()
Section titled “add() ”abstract public function add(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): boolAdds a role, permission or rule to the RBAC system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$object | Role|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)
addChild()
Section titled “addChild() ”abstract public function addChild(yii\rbac\Item $parent, yii\rbac\Item $child): boolAdds an item as a child of another item.
Parameters
| Parameter | Type | Description |
|---|---|---|
$parent | Item | |
$child | Item |
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.
assign()
Section titled “assign() ”abstract public function assign(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): yii\rbac\AssignmentAssigns a role to a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$role | Role|Permission | |
$userId | string| | The user ID (see User::$id) |
Returns
Assignment: The role assignment information.
Throws
Exception: if the role has already been assigned to the user
canAddChild()
Section titled “canAddChild() ”abstract public function canAddChild(yii\rbac\Item $parent, yii\rbac\Item $child): boolChecks the possibility of adding a child to parent.
createPermission()
Section titled “createPermission() ”abstract public function createPermission(string $name): yii\rbac\PermissionCreates 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
| Parameter | Type | Description |
|---|---|---|
$name | string | The permission name |
Returns
Permission: The new Permission object
createRole()
Section titled “createRole() ”abstract public function createRole(string $name): yii\rbac\RoleCreates 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.
getAssignment()
Section titled “getAssignment() ”abstract public function getAssignment(string $roleName, string|int $userId): yii\rbac\Assignment|nullReturns the assignment information regarding a role and a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string | The role name |
$userId | string| | The user ID (see User::$id) |
Returns
Assignment|null: The assignment information. Null is returned if the role is not assigned to the user.
getAssignments()
Section titled “getAssignments() ”abstract public function getAssignments(string|int $userId): yii\rbac\Assignment[]Returns all role assignment information for the specified user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$userId | string| | The 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.
getChildren()
Section titled “getChildren() ”abstract public function getChildren(string $name): yii\rbac\Item[]Returns the child permissions and/or roles.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The parent name |
Returns
Item[]: The child permissions and/or roles
getChildRoles()
Section titled “getChildRoles() ”abstract public function getChildRoles(string $roleName): yii\rbac\Role[]Returns child roles of the role specified. Depth isn’t limited.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string | Name 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
yii\base\InvalidArgumentException: if Role was not found that are getting by $roleName
Since
2.0.10
getPermission()
Section titled “getPermission() ”abstract public function getPermission(string $name): yii\rbac\Permission|nullReturns the named permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The permission name. |
Returns
Permission|null: The permission corresponding to the specified name. Null is returned if no such permission.
getPermissions()
Section titled “getPermissions() ”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.
getPermissionsByRole()
Section titled “getPermissionsByRole() ”abstract public function getPermissionsByRole(string $roleName): yii\rbac\Permission[]Returns all permissions that the specified role represents.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string | The role name |
Returns
Permission[]: All permissions that the role represents. The array is indexed by the permission names.
getPermissionsByUser()
Section titled “getPermissionsByUser() ”abstract public function getPermissionsByUser(string|int $userId): yii\rbac\Permission[]Returns all permissions that the user has.
Parameters
| Parameter | Type | Description |
|---|---|---|
$userId | string| | The user ID (see User::$id) |
Returns
Permission[]: All permissions that the user has. The array is indexed by the permission names.
getRole()
Section titled “getRole() ”abstract public function getRole(string $name): yii\rbac\Role|nullReturns the named role.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The role name. |
Returns
Role|null: The role corresponding to the specified name. Null is returned if no such role.
getRoles()
Section titled “getRoles() ”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.
getRolesByUser()
Section titled “getRolesByUser() ”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.
getRule()
Section titled “getRule() ”abstract public function getRule(string $name): yii\rbac\Rule|nullReturns the rule of the specified name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The rule name |
Returns
Rule|null: The rule object, or null if the specified name does not correspond to a rule.
getRules()
Section titled “getRules() ”abstract public function getRules(): yii\rbac\Rule[]Returns all rules available in the system.
Returns
Rule[]: The rules indexed by the rule names
getUserIdsByRole()
Section titled “getUserIdsByRole() ”abstract public function getUserIdsByRole(string $roleName): arrayReturns all user IDs assigned to the role specified.
Parameters
| Parameter | Type | Description |
|---|---|---|
$roleName | string |
Returns
array: Array of user ID strings
Since
2.0.7
hasChild()
Section titled “hasChild() ”abstract public function hasChild(yii\rbac\Item $parent, yii\rbac\Item $child): boolReturns a value indicating whether the child already exists for the parent.
remove()
Section titled “remove() ”abstract public function remove(yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): boolRemoves a role, permission or rule from the RBAC system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$object | Role|Permission|Rule |
Returns
bool: Whether the role, permission or rule is successfully removed
removeAll()
Section titled “removeAll() ”abstract public function removeAll(): mixedRemoves all authorization data, including roles, permissions, rules, and assignments.
Returns
mixed
removeAllAssignments()
Section titled “removeAllAssignments() ”abstract public function removeAllAssignments(): mixedRemoves all role assignments.
Returns
mixed
removeAllPermissions()
Section titled “removeAllPermissions() ”abstract public function removeAllPermissions(): mixedRemoves all permissions.
All parent child relations will be adjusted accordingly.
Returns
mixed
removeAllRoles()
Section titled “removeAllRoles() ”abstract public function removeAllRoles(): mixedRemoves all roles.
All parent child relations will be adjusted accordingly.
Returns
mixed
removeAllRules()
Section titled “removeAllRules() ”abstract public function removeAllRules(): mixedRemoves all rules.
All roles and permissions which have rules will be adjusted accordingly.
Returns
mixed
removeChild()
Section titled “removeChild() ”abstract public function removeChild(yii\rbac\Item $parent, yii\rbac\Item $child): boolRemoves a child from its parent.
Note, the child item is not deleted. Only the parent-child relationship is removed.
removeChildren()
Section titled “removeChildren() ”abstract public function removeChildren(yii\rbac\Item $parent): boolRemoved all children form their parent.
Note, the children items are not deleted. Only the parent-child relationships are removed.
revoke()
Section titled “revoke() ”abstract public function revoke(yii\rbac\Role|yii\rbac\Permission $role, string|int $userId): boolRevokes a role from a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$role | Role|Permission | |
$userId | string| | The user ID (see User::$id) |
Returns
bool: Whether the revoking is successful
revokeAll()
Section titled “revokeAll() ”abstract public function revokeAll(mixed $userId): boolRevokes all roles from a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
$userId | mixed | The user ID (see User::$id) |
Returns
bool: Whether the revoking is successful
update()
Section titled “update() ”abstract public function update(string $name, yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule $object): boolUpdates the specified role, permission or rule in the system.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The old name of the role, permission or rule |
$object | Role|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)