Abstract Class yii\rbac\BaseManager

继承yii\rbac\BaseManager » yii\base\Component » yii\base\BaseObject
实现yii\base\Configurable, yii\rbac\ManagerInterface
子类yii\rbac\DbManager, yii\rbac\PhpManager
可用自版本2.0
源代码 https://github.com/yiisoft/yii2/blob/master/framework/rbac/BaseManager.php

BaseManager is a base class implementing yii\rbac\ManagerInterface for RBAC management.

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

公共属性

隐藏继承的属性

属性类型描述定义在
$behaviors yii\base\Behavior[] 附加到此组件的行为列表. 该属性是只读的. yii\base\Component
$defaultRoleInstances yii\rbac\Role[] Default roles. The array is indexed by the role names. This property is read-only. yii\rbac\BaseManager
$permissions yii\rbac\Permission[] All permissions in the system. yii\rbac\BaseManager
$roles yii\rbac\Role[] All roles in the system. yii\rbac\BaseManager
$rules yii\rbac\Rule[] The rules indexed by the rule names yii\rbac\ManagerInterface

受保护的属性

隐藏继承的属性

属性类型描述定义在
$defaultRoles array A list of role names that are assigned to every user automatically without calling assign(). yii\rbac\BaseManager

公共方法

隐藏继承的方法

方法描述定义在
__call() 调用不是类方法的指定的方法. yii\base\Component
__clone() 在通过克隆现有对象创建对象之后调用此方法. yii\base\Component
__construct() 构造函数. yii\base\BaseObject
__get() 返回组件属性的值. yii\base\Component
__isset() 检查属性是否已设置, 即已定义且不为null. yii\base\Component
__set() 设置组件属性的值. yii\base\Component
__unset() 将组件属性设置为null. yii\base\Component
add() Adds a role, permission or rule to the RBAC system. yii\rbac\BaseManager
addChild() Adds an item as a child of another item. yii\rbac\ManagerInterface
assign() Assigns a role to a user. yii\rbac\ManagerInterface
attachBehavior() 将行为附加到此组件. yii\base\Component
attachBehaviors() 将行为列表附加到组件. yii\base\Component
behaviors() 返回此组件应该具有的行为列表. yii\base\Component
canAddChild() Checks the possibility of adding a child to parent. yii\rbac\ManagerInterface
canGetProperty() 返回一个值, 指示属性是否可读取. yii\base\Component
canSetProperty() 返回一个值, 指示属性是否可设置. yii\base\Component
className() 返回此类的完全限定名称. yii\base\BaseObject
createPermission() Creates a new Permission object. yii\rbac\BaseManager
createRole() Creates a new Role object. yii\rbac\BaseManager
detachBehavior() 从组件中分离一个行为. yii\base\Component
detachBehaviors() 分离组件中的所有行为. yii\base\Component
ensureBehaviors() 确保在 behaviors() 中声明的行为已附加到此组件. yii\base\Component
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
getBehavior() 返回指定的行为对象. yii\base\Component
getBehaviors() 返回附加到此组件的所有行为. yii\base\Component
getChildRoles() Returns child roles of the role specified. Depth isn't limited. yii\rbac\ManagerInterface
getChildren() Returns the child permissions and/or roles. yii\rbac\ManagerInterface
getDefaultRoleInstances() Returns defaultRoles as array of Role objects. yii\rbac\BaseManager
getDefaultRoles() Get default roles yii\rbac\BaseManager
getPermission() Returns the named permission. yii\rbac\BaseManager
getPermissions() Returns all permissions in the system. yii\rbac\BaseManager
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\BaseManager
getRoles() Returns all roles in the system. yii\rbac\BaseManager
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
getUserIdsByRole() Returns all user IDs assigned to the role specified. yii\rbac\ManagerInterface
hasChild() Returns a value indicating whether the child already exists for the parent. yii\rbac\ManagerInterface
hasEventHandlers() 返回一个值, 指示是否有任何处理程序附加到指定的事件. yii\base\Component
hasMethod() 返回一个值, 指示方法是否已定义. yii\base\Component
hasProperty() 返回一个值, 指示属性是否已定义. yii\base\Component
init() 初始化对象. yii\base\BaseObject
off() 从该组件分离现有的事件处理程序. yii\base\Component
on() 将事件处理程序附加到事件. yii\base\Component
remove() Removes a role, permission or rule from the RBAC system. yii\rbac\BaseManager
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
setDefaultRoles() Set default roles yii\rbac\BaseManager
trigger() 触发事件. yii\base\Component
update() Updates the specified role, permission or rule in the system. yii\rbac\BaseManager

受保护的方法

隐藏继承的方法

方法描述定义在
addItem() Adds an auth item to the RBAC system. yii\rbac\BaseManager
addRule() Adds a rule to the RBAC system. yii\rbac\BaseManager
executeRule() Executes the rule associated with the specified auth item. yii\rbac\BaseManager
getItem() Returns the named auth item. yii\rbac\BaseManager
getItems() Returns the items of the specified type. yii\rbac\BaseManager
hasNoAssignments() Checks whether array of $assignments is empty and $defaultRoles property is empty as well. yii\rbac\BaseManager
removeItem() Removes an auth item from the RBAC system. yii\rbac\BaseManager
removeRule() Removes a rule from the RBAC system. yii\rbac\BaseManager
updateItem() Updates an auth item in the RBAC system. yii\rbac\BaseManager
updateRule() Updates a rule to the RBAC system. yii\rbac\BaseManager

属性详情

$defaultRoleInstances public 属性

Default roles. The array is indexed by the role names. This property is read-only.

$defaultRoles protected 属性

A list of role names that are assigned to every user automatically without calling assign(). Note that these roles are applied to users, regardless of their state of authentication.

protected array $defaultRoles = []
$permissions public 只读 属性

All permissions in the system. The array is indexed by the permission names.

$roles public 只读 属性

All roles in the system. The array is indexed by the role names.

public yii\rbac\Role[] getRoles ( )

方法详情

add() public 方法

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

public 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)

addItem() protected abstract 方法

Adds an auth item to the RBAC system.

protected abstract boolean addItem ( $item )
$item yii\rbac\Item

The item to add

return boolean

Whether the auth item 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)

addRule() protected abstract 方法

Adds a rule to the RBAC system.

protected abstract boolean addRule ( $rule )
$rule yii\rbac\Rule

The rule to add

return boolean

Whether the rule is successfully added to the system

throws Exception

if data validation or saving fails (such as the name of the rule is not unique)

createPermission() public 方法

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.

public yii\rbac\Permission createPermission ( $name )
$name string

The permission name

return yii\rbac\Permission

The new Permission object

createRole() public 方法

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.

public yii\rbac\Role createRole ( $name )
$name string

The role name

return yii\rbac\Role

The new Role object

executeRule() protected 方法

Executes the rule associated with the specified auth item.

If the item does not specify a rule, this method will return true. Otherwise, it will return the value of yii\rbac\Rule::execute().

protected boolean executeRule ( $user, $item, $params )
$user 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.

$item yii\rbac\Item

The auth item that needs to execute its rule

$params array

Parameters passed to yii\rbac\CheckAccessInterface::checkAccess() and will be passed to the rule

return boolean

The return value of yii\rbac\Rule::execute(). If the auth item does not specify a rule, true will be returned.

throws yii\base\InvalidConfigException

if the auth item has an invalid rule.

getDefaultRoleInstances() public 方法 (可用自版本: 2.0.12)

Returns defaultRoles as array of Role objects.

public yii\rbac\Role[] getDefaultRoleInstances ( )
return yii\rbac\Role[]

Default roles. The array is indexed by the role names

getDefaultRoles() public 方法 (可用自版本: 2.0.14)

Get default roles

public string[] getDefaultRoles ( )
return string[]

Default roles

getItem() protected abstract 方法

Returns the named auth item.

protected abstract yii\rbac\Item getItem ( $name )
$name string

The auth item name.

return yii\rbac\Item

The auth item corresponding to the specified name. Null is returned if no such item.

getItems() protected abstract 方法

Returns the items of the specified type.

protected abstract yii\rbac\Item[] getItems ( $type )
$type integer

The auth item type (either yii\rbac\Item::TYPE_ROLE or yii\rbac\Item::TYPE_PERMISSION

return yii\rbac\Item[]

The auth items of the specified type.

getPermission() public 方法

Returns the named permission.

public 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.

getPermissions() public 方法

Returns all permissions in the system.

public yii\rbac\Permission[] getPermissions ( )
return yii\rbac\Permission[]

All permissions in the system. The array is indexed by the permission names.

getRole() public 方法

Returns the named role.

public 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.

getRoles() public 方法

Returns all roles in the system.

public yii\rbac\Role[] getRoles ( )
return yii\rbac\Role[]

All roles in the system. The array is indexed by the role names.

hasNoAssignments() protected 方法 (可用自版本: 2.0.11)

Checks whether array of $assignments is empty and $defaultRoles property is empty as well.

protected boolean hasNoAssignments ( array $assignments )
$assignments yii\rbac\Assignment[]

Array of user's assignments

return boolean

Whether array of $assignments is empty and $defaultRoles property is empty as well

remove() public 方法

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

public boolean remove ( $object )
$object yii\rbac\Role|yii\rbac\Permission|yii\rbac\Rule
return boolean

Whether the role, permission or rule is successfully removed

removeItem() protected abstract 方法

Removes an auth item from the RBAC system.

protected abstract boolean removeItem ( $item )
$item yii\rbac\Item

The item to remove

return boolean

Whether the role or permission is successfully removed

throws Exception

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

removeRule() protected abstract 方法

Removes a rule from the RBAC system.

protected abstract boolean removeRule ( $rule )
$rule yii\rbac\Rule

The rule to remove

return boolean

Whether the rule is successfully removed

throws Exception

if data validation or saving fails (such as the name of the rule is not unique)

setDefaultRoles() public 方法 (可用自版本: 2.0.14)

Set default roles

public void setDefaultRoles ( $roles )
$roles string[]|Closure

Either array of roles or a callable returning it

throws yii\base\InvalidArgumentException

when $roles is neither array nor Closure

throws yii\base\InvalidValueException

when Closure return is not an array

update() public 方法

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

public 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)

updateItem() protected abstract 方法

Updates an auth item in the RBAC system.

protected abstract boolean updateItem ( $name, $item )
$name string

The name of the item being updated

$item yii\rbac\Item

The updated item

return boolean

Whether the auth item is successfully updated

throws Exception

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

updateRule() protected abstract 方法

Updates a rule to the RBAC system.

protected abstract boolean updateRule ( $name, $rule )
$name string

The name of the rule being updated

$rule yii\rbac\Rule

The updated rule

return boolean

Whether the rule is successfully updated

throws Exception

if data validation or saving fails (such as the name of the rule is not unique)