Interface yii\rbac\ManagerInterface
Implemented by | yii\rbac\BaseManager, yii\rbac\DbManager, yii\rbac\PhpManager |
---|---|
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/rbac/ManagerInterface.php |
Public Methods
Method | Description | Defined By |
---|---|---|
add() | Adds a role, permission or rule to the RBAC system. | yii\rbac\ManagerInterface |
addChild() | Adds an item as a child of another item. | yii\rbac\ManagerInterface |
assign() | Assigns a role to a user. | yii\rbac\ManagerInterface |
checkAccess() | Checks if the user has the specified permission. | yii\rbac\ManagerInterface |
createPermission() | Creates a new Permission object. | yii\rbac\ManagerInterface |
createRole() | Creates a new Role object. | yii\rbac\ManagerInterface |
getAssignment() | Returns the assignment information regarding a role and a user. | yii\rbac\ManagerInterface |
getAssignments() | Returns all role assignment information for the specified user. | yii\rbac\ManagerInterface |
getChildren() | Returns the child permissions and/or roles. | yii\rbac\ManagerInterface |
getPermission() | Returns the named permission. | yii\rbac\ManagerInterface |
getPermissions() | Returns all permissions in the system. | yii\rbac\ManagerInterface |
getPermissionsByRole() | Returns all permissions that the specified role represents. | yii\rbac\ManagerInterface |
getPermissionsByUser() | Returns all permissions that the user has. | yii\rbac\ManagerInterface |
getRole() | Returns the named role. | yii\rbac\ManagerInterface |
getRoles() | Returns all roles in the system. | yii\rbac\ManagerInterface |
getRolesByUser() | Returns the roles that are assigned to the user via assign(). | yii\rbac\ManagerInterface |
getRule() | Returns the rule of the specified name. | yii\rbac\ManagerInterface |
getRules() | Returns all rules available in the system. | yii\rbac\ManagerInterface |
hasChild() | Returns a value indicating whether the child already exists for the parent. | yii\rbac\ManagerInterface |
remove() | Removes a role, permission or rule from the RBAC system. | yii\rbac\ManagerInterface |
removeAll() | Removes all authorization data, including roles, permissions, rules, and assignments. | yii\rbac\ManagerInterface |
removeAllAssignments() | Removes all role assignments. | yii\rbac\ManagerInterface |
removeAllPermissions() | Removes all permissions. | yii\rbac\ManagerInterface |
removeAllRoles() | Removes all roles. | yii\rbac\ManagerInterface |
removeAllRules() | Removes all rules. | yii\rbac\ManagerInterface |
removeChild() | Removes a child from its parent. | yii\rbac\ManagerInterface |
removeChildren() | Removed all children form their parent. | yii\rbac\ManagerInterface |
revoke() | Revokes a role from a user. | yii\rbac\ManagerInterface |
revokeAll() | Revokes all roles from a user. | yii\rbac\ManagerInterface |
update() | Updates the specified role, permission or rule in the system. | yii\rbac\ManagerInterface |
Method Details
Adds a role, permission or rule to the RBAC system.
boolean add( $object ) | ||
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | 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) |
Adds an item as a child of another item.
void addChild( $parent, $child ) | ||
$parent | yii\rbac\Item | |
$child | yii\rbac\Item | |
throws | yii\base\Exception | if the parent-child relationship already exists or if a loop has been detected. |
---|
Assigns a role to a user.
yii\rbac\Assignment assign( $role, $userId ) | ||
$role | yii\rbac\Role | |
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | yii\rbac\Assignment | The role assignment information. |
---|---|---|
throws | Exception | if the role has already been assigned to the user |
Checks if the user has the specified permission.
boolean checkAccess( $userId, $permissionName, $params = [] ) | ||
$userId | string|integer | The user ID. This should be either an integer or a string representing the unique identifier of a user. See yii\web\User::$id. |
$permissionName | string | The name of the permission to be checked against |
$params | array | Name-value pairs that will be passed to the rules associated with the roles and permissions assigned to the user. |
return | boolean | Whether the user has the specified permission. |
---|---|---|
throws | yii\base\InvalidParamException | if $permissionName does not refer to an existing 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.
yii\rbac\Permission createPermission( $name ) | ||
$name | string | The permission name |
return | yii\rbac\Permission | The new Permission object |
---|
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.
yii\rbac\Role createRole( $name ) | ||
$name | string | The role name |
return | yii\rbac\Role | The new Role object |
---|
Returns the assignment information regarding a role and a user.
null|yii\rbac\Assignment getAssignment( $roleName, $userId ) | ||
$roleName | string | The role name |
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | null|yii\rbac\Assignment | The assignment information. Null is returned if the role is not assigned to the user. |
---|
Returns all role assignment information for the specified user.
yii\rbac\Assignment[] getAssignments( $userId ) | ||
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | yii\rbac\Assignment[] | The assignments indexed by role names. An empty array will be returned if there is no role assigned to the user. |
---|
Returns the child permissions and/or roles.
yii\rbac\Item[] getChildren( $name ) | ||
$name | string | The parent name |
return | yii\rbac\Item[] | The child permissions and/or roles |
---|
Returns the named permission.
null|yii\rbac\Permission getPermission( $name ) | ||
$name | string | The permission name. |
return | null|yii\rbac\Permission | The permission corresponding to the specified name. Null is returned if no such permission. |
---|
Returns all permissions in the system.
yii\rbac\Permission[] getPermissions( ) | ||
return | yii\rbac\Permission[] | All permissions in the system. The array is indexed by the permission names. |
---|
Returns all permissions that the specified role represents.
yii\rbac\Permission[] getPermissionsByRole( $roleName ) | ||
$roleName | string | The role name |
return | yii\rbac\Permission[] | All permissions that the role represents. The array is indexed by the permission names. |
---|
Returns all permissions that the user has.
yii\rbac\Permission[] getPermissionsByUser( $userId ) | ||
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | yii\rbac\Permission[] | All permissions that the user has. The array is indexed by the permission names. |
---|
Returns the named role.
null|yii\rbac\Role getRole( $name ) | ||
$name | string | The role name. |
return | null|yii\rbac\Role | The role corresponding to the specified name. Null is returned if no such role. |
---|
Returns all roles in the system.
yii\rbac\Role[] getRoles( ) | ||
return | yii\rbac\Role[] | All roles in the system. The array is indexed by the role names. |
---|
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.
yii\rbac\Role[] getRolesByUser( $userId ) | ||
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | yii\rbac\Role[] | All roles directly or indirectly assigned to the user. The array is indexed by the role names. |
---|
Returns the rule of the specified name.
null|yii\rbac\Rule getRule( $name ) | ||
$name | string | The rule name |
return | null|yii\rbac\Rule | The rule object, or null if the specified name does not correspond to a rule. |
---|
Returns all rules available in the system.
yii\rbac\Rule[] getRules( ) | ||
return | yii\rbac\Rule[] | The rules indexed by the rule names |
---|
Returns a value indicating whether the child already exists for the parent.
boolean hasChild( $parent, $child ) | ||
$parent | yii\rbac\Item | |
$child | yii\rbac\Item | |
return | boolean | Whether |
---|
Removes a role, permission or rule from the RBAC system.
boolean remove( $object ) | ||
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | Whether the role, permission or rule is successfully removed |
---|
Removes all authorization data, including roles, permissions, rules, and assignments.
void removeAll( ) |
Removes all role assignments.
void removeAllAssignments( ) |
Removes all permissions.
All parent child relations will be adjusted accordingly.
void removeAllPermissions( ) |
Removes all roles.
All parent child relations will be adjusted accordingly.
void removeAllRoles( ) |
Removes all rules.
All roles and permissions which have rules will be adjusted accordingly.
void removeAllRules( ) |
Removes a child from its parent.
Note, the child item is not deleted. Only the parent-child relationship is removed.
boolean removeChild( $parent, $child ) | ||
$parent | yii\rbac\Item | |
$child | yii\rbac\Item | |
return | boolean | Whether the removal is successful |
---|
Removed all children form their parent.
Note, the children items are not deleted. Only the parent-child relationships are removed.
boolean removeChildren( $parent ) | ||
$parent | yii\rbac\Item | |
return | boolean | Whether the removal is successful |
---|
Revokes a role from a user.
boolean revoke( $role, $userId ) | ||
$role | yii\rbac\Role | |
$userId | string|integer | The user ID (see yii\web\User::$id) |
return | boolean | Whether the revoking is successful |
---|
Revokes all roles from a user.
boolean revokeAll( $userId ) | ||
$userId | mixed | The user ID (see yii\web\User::$id) |
return | boolean | Whether the revoking is successful |
---|
Updates the specified role, permission or rule in the system.
boolean update( $name, $object ) | ||
$name | string | The old name of the role, permission or rule |
$object | yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule | |
return | boolean | 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) |