PHP Interface yii\rbac\ManagerInterface

Since: 2.0
Author: Qiang Xue ([email protected])
Show file Open project: yiisoft/yii2 Interface Usage Examples

Public Methods

Method Description
add ( Role | Permission | Rule $object ) : boolean Adds a role, permission or rule to the RBAC system.
addChild ( Item $parent, Item $child ) : boolean Adds an item as a child of another item.
assign ( Role $role, string | integer $userId ) : Assignment Assigns a role to a user.
canAddChild ( Item $parent, Item $child ) : boolean Checks the possibility of adding a child to parent
createPermission ( string $name ) : Permission Creates a new Permission object.
createRole ( string $name ) : Role Creates a new Role object.
getAssignment ( string $roleName, string | integer $userId ) : null | Assignment Returns the assignment information regarding a role and a user.
getAssignments ( string | integer $userId ) : Assignment[] Returns all role assignment information for the specified user.
getChildRoles ( string $roleName ) : Role[] Returns child roles of the role specified. Depth isn't limited.
getChildren ( string $name ) : Item[] Returns the child permissions and/or roles.
getPermission ( string $name ) : null | Permission Returns the named permission.
getPermissions ( ) : Permission[] Returns all permissions in the system.
getPermissionsByRole ( string $roleName ) : Permission[] Returns all permissions that the specified role represents.
getPermissionsByUser ( string | integer $userId ) : Permission[] Returns all permissions that the user has.
getRole ( string $name ) : null | Role Returns the named role.
getRoles ( ) : Role[] Returns all roles in the system.
getRolesByUser ( string | integer $userId ) : Role[] Returns the roles that are assigned to the user via ManagerInterface::assign.
getRule ( string $name ) : null | Rule Returns the rule of the specified name.
getRules ( ) : Rule[] Returns all rules available in the system.
getUserIdsByRole ( string $roleName ) : array Returns all user IDs assigned to the role specified.
hasChild ( Item $parent, Item $child ) : boolean Returns a value indicating whether the child already exists for the parent.
remove ( Role | Permission | Rule $object ) : boolean Removes a role, permission or rule from the RBAC system.
removeAll ( ) Removes all authorization data, including roles, permissions, rules, and assignments.
removeAllAssignments ( ) Removes all role assignments.
removeAllPermissions ( ) Removes all permissions.
removeAllRoles ( ) Removes all roles.
removeAllRules ( ) Removes all rules.
removeChild ( Item $parent, Item $child ) : boolean Removes a child from its parent.
removeChildren ( Item $parent ) : boolean Removed all children form their parent.
revoke ( Role $role, string | integer $userId ) : boolean Revokes a role from a user.
revokeAll ( mixed $userId ) : boolean Revokes all roles from a user.
update ( string $name, Role | Permission | Rule $object ) : boolean Updates the specified role, permission or rule in the system.

Method Details

add() public method

Adds a role, permission or rule to the RBAC system.
public add ( Role | Permission | Rule $object ) : boolean
$object Role | Permission | Rule
return boolean whether the role, permission or rule is successfully added to the system

addChild() public method

Adds an item as a child of another item.
public addChild ( Item $parent, Item $child ) : boolean
$parent Item
$child Item
return boolean whether the child successfully added

assign() public method

Assigns a role to a user.
public assign ( Role $role, string | integer $userId ) : Assignment
$role Role
$userId string | integer the user ID (see [[\yii\web\User::id]])
return Assignment the role assignment information.

canAddChild() public method

Checks the possibility of adding a child to parent
Since: 2.0.8
public canAddChild ( Item $parent, Item $child ) : boolean
$parent Item the parent item
$child Item the child item to be added to the hierarchy
return boolean possibility of adding

createPermission() public method

Note that the newly created permission is not added to the RBAC system yet. You must fill in the needed data and call ManagerInterface::add to add it to the system.
public createPermission ( string $name ) : Permission
$name string the permission name
return Permission the new Permission object

createRole() public method

Note that the newly created role is not added to the RBAC system yet. You must fill in the needed data and call ManagerInterface::add to add it to the system.
public createRole ( string $name ) : Role
$name string the role name
return Role the new Role object

getAssignment() public method

Returns the assignment information regarding a role and a user.
public getAssignment ( string $roleName, string | integer $userId ) : null | Assignment
$roleName string the role name
$userId string | integer the user ID (see [[\yii\web\User::id]])
return null | Assignment the assignment information. Null is returned if the role is not assigned to the user.

getAssignments() public method

Returns all role assignment information for the specified user.
public getAssignments ( string | integer $userId ) : Assignment[]
$userId string | integer the user ID (see [[\yii\web\User::id]])
return Assignment[] the assignments indexed by role names. An empty array will be returned if there is no role assigned to the user.

getChildRoles() public method

Returns child roles of the role specified. Depth isn't limited.
Since: 2.0.10
public getChildRoles ( string $roleName ) : Role[]
$roleName string name of the role to file child roles for
return Role[] Child roles. The array is indexed by the role names. First element is an instance of the parent Role itself.

getChildren() public method

Returns the child permissions and/or roles.
public getChildren ( string $name ) : Item[]
$name string the parent name
return Item[] the child permissions and/or roles

getPermission() public method

Returns the named permission.
public getPermission ( string $name ) : null | Permission
$name string the permission name.
return null | Permission the permission corresponding to the specified name. Null is returned if no such permission.

getPermissions() public method

Returns all permissions in the system.
public getPermissions ( ) : Permission[]
return Permission[] all permissions in the system. The array is indexed by the permission names.

getPermissionsByRole() public method

Returns all permissions that the specified role represents.
public getPermissionsByRole ( string $roleName ) : Permission[]
$roleName string the role name
return Permission[] all permissions that the role represents. The array is indexed by the permission names.

getPermissionsByUser() public method

Returns all permissions that the user has.
public getPermissionsByUser ( string | integer $userId ) : Permission[]
$userId string | integer the user ID (see [[\yii\web\User::id]])
return Permission[] all permissions that the user has. The array is indexed by the permission names.

getRole() public method

Returns the named role.
public getRole ( string $name ) : null | Role
$name string the role name.
return null | Role the role corresponding to the specified name. Null is returned if no such role.

getRoles() public method

Returns all roles in the system.
public getRoles ( ) : Role[]
return Role[] all roles in the system. The array is indexed by the role names.

getRolesByUser() public method

Note that child roles that are not assigned directly to the user will not be returned.
public getRolesByUser ( string | integer $userId ) : Role[]
$userId string | integer the user ID (see [[\yii\web\User::id]])
return Role[] all roles directly assigned to the user. The array is indexed by the role names.

getRule() public method

Returns the rule of the specified name.
public getRule ( string $name ) : null | Rule
$name string the rule name
return null | Rule the rule object, or null if the specified name does not correspond to a rule.

getRules() public method

Returns all rules available in the system.
public getRules ( ) : Rule[]
return Rule[] the rules indexed by the rule names

getUserIdsByRole() public method

Returns all user IDs assigned to the role specified.
Since: 2.0.7
public getUserIdsByRole ( string $roleName ) : array
$roleName string
return array array of user ID strings

hasChild() public method

Returns a value indicating whether the child already exists for the parent.
public hasChild ( Item $parent, Item $child ) : boolean
$parent Item
$child Item
return boolean whether `$child` is already a child of `$parent`

remove() public method

Removes a role, permission or rule from the RBAC system.
public remove ( Role | Permission | Rule $object ) : boolean
$object Role | Permission | Rule
return boolean whether the role, permission or rule is successfully removed

removeAll() public method

Removes all authorization data, including roles, permissions, rules, and assignments.
public removeAll ( )

removeAllAssignments() public method

Removes all role assignments.

removeAllPermissions() public method

All parent child relations will be adjusted accordingly.

removeAllRoles() public method

All parent child relations will be adjusted accordingly.
public removeAllRoles ( )

removeAllRules() public method

All roles and permissions which have rules will be adjusted accordingly.
public removeAllRules ( )

removeChild() public method

Note, the child item is not deleted. Only the parent-child relationship is removed.
public removeChild ( Item $parent, Item $child ) : boolean
$parent Item
$child Item
return boolean whether the removal is successful

removeChildren() public method

Note, the children items are not deleted. Only the parent-child relationships are removed.
public removeChildren ( Item $parent ) : boolean
$parent Item
return boolean whether the removal is successful

revoke() public method

Revokes a role from a user.
public revoke ( Role $role, string | integer $userId ) : boolean
$role Role
$userId string | integer the user ID (see [[\yii\web\User::id]])
return boolean whether the revoking is successful

revokeAll() public method

Revokes all roles from a user.
public revokeAll ( mixed $userId ) : boolean
$userId mixed the user ID (see [[\yii\web\User::id]])
return boolean whether the revoking is successful

update() public method

Updates the specified role, permission or rule in the system.
public update ( string $name, Role | Permission | Rule $object ) : boolean
$name string the old name of the role, permission or rule
$object Role | Permission | Rule
return boolean whether the update is successful