没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

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/yiichina/yii2/blob/api/framework/rbac/BaseManager.php

BaseManager 是实现 RBAC 管理 yii\rbac\ManagerInterface 的基类。

有关 DbManager 的更多详细信息和用法信息,请参阅 授权指南

公共属性

隐藏继承的属性

属性类型描述被定义在
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$defaultRoleInstances yii\rbac\Role[] 默认角色。该数组由角色名称索引 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 在不调用 assign() 的情况下自动分配给每个用户的角色名称列表。 请注意,无论身份验证的状态如何,这些角色都将应用于用户。 yii\rbac\BaseManager

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be 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() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canAddChild() Checks the possibility of adding a child to parent. yii\rbac\ManagerInterface
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
createPermission() Creates a new Permission object. yii\rbac\BaseManager
createRole() Creates a new Role object. yii\rbac\BaseManager
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. 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() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. 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() 将 defaultRoles 作为 Role 对象的数组返回。 yii\rbac\BaseManager
getDefaultRoles() 获取默认角色 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() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. 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() 设置默认角色 yii\rbac\BaseManager
trigger() Triggers an event. yii\base\Component
update() Updates the specified role, permission or rule in the system. yii\rbac\BaseManager

受保护的方法

隐藏继承的方法

方法描述被定义在
addItem() 将一个 auth 项添加到 RBAC 系统。 yii\rbac\BaseManager
addRule() 向 RBAC 系统添加规则。 yii\rbac\BaseManager
executeRule() 执行与指定 auth 项关联的规则。 yii\rbac\BaseManager
getItem() 返回指定的 auth 项。 yii\rbac\BaseManager
getItems() 返回指定类型的项。 yii\rbac\BaseManager
hasNoAssignments() 检查 $assignment 和 $defaultRoles 数组是否都为空。 yii\rbac\BaseManager
removeItem() 从 RBAC 系统中删除 auth 项。 yii\rbac\BaseManager
removeRule() 从 RBAC 系统中删除规则。 yii\rbac\BaseManager
updateItem() 更新 RBAC 系统中的 auth 项。 yii\rbac\BaseManager
updateRule() 更新 RBAC 系统中的规则。 yii\rbac\BaseManager

属性详情

$defaultRoleInstances 公共 只读 属性

默认角色。该数组由角色名称索引

$defaultRoles 受保护 属性

在不调用 assign() 的情况下自动分配给每个用户的角色名称列表。 请注意,无论身份验证的状态如何,这些角色都将应用于用户。

public string[] getDefaultRoles ( )
public void setDefaultRoles ( $roles )
$permissions 公共 只读 属性

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

$roles 公共 只读 属性

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

public yii\rbac\Role[] getRoles ( )

方法详情

add() 公共 方法

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() 受保护 抽象 方法

将一个 auth 项添加到 RBAC 系统。

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

要添加的项目

return boolean

是否已成功将 auth 项添加到系统中

throws Exception

如果数据验证或保存失败(例如角色名称或权限不唯一)

addRule() 受保护 抽象 方法

向 RBAC 系统添加规则。

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

要添加的规则

return boolean

规则是否已成功添加到系统中

throws Exception

如果数据验证或保存失败(例如规则名称不唯一)

createPermission() 公共 方法

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() 公共 方法

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() 受保护 方法

执行与指定 auth 项关联的规则。

如果项目未指定规则,则此方法将返回 true。 否则返回 yii\rbac\Rule::execute() 的值。

protected boolean executeRule($user, $item, $params)
$user string|integer

用户 ID。这应该是整数或字符串, 表示用户的唯一标识符。参阅 yii\web\User::$id

$item yii\rbac\Item

需要执行其规则的 auth 项

$params array

传递给 yii\rbac\CheckAccessInterface::checkAccess() 的参数,并且也将传递给规则

return boolean

yii\rbac\Rule::execute() 的返回值。如果 auth 项目未指定规则,则返回 true。

throws yii\base\InvalidConfigException

如果 auth 项目有无效规则。

getDefaultRoleInstances() 公共 方法 (自版本 2.0.12 可用)

将 defaultRoles 作为 Role 对象的数组返回。

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

默认角色。该数组由角色名称索引

getDefaultRoles() 公共 方法 (自版本 2.0.14 可用)

获取默认角色

public string[] getDefaultRoles()
return string[]

默认角色

getItem() 受保护 抽象 方法

返回指定的 auth 项。

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

Auth 项的名称。

return yii\rbac\Item

与指定名称对应的 auth 项。如果没有这样的项目,则返回 Null。

getItems() 受保护 抽象 方法

返回指定类型的项。

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

Auth 项类型(yii\rbac\Item::TYPE_ROLEyii\rbac\Item::TYPE_PERMISSION

return yii\rbac\Item[]

指定类型的 auth 项。

getPermission() 公共 方法

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() 公共 方法

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() 公共 方法

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() 公共 方法

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() 受保护 方法 (自版本 2.0.11 可用)

检查 $assignment 和 $defaultRoles 数组是否都为空。

protected boolean hasNoAssignments(array $assignments)
$assignments
return boolean

$assignment 和 $defaultRoles 数组是否都为空

remove() 公共 方法

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() 受保护 抽象 方法

从 RBAC 系统中删除 auth 项。

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

要删除的项目

return boolean

是否成功删除了角色或权限

throws Exception

如果数据验证或保存失败(例如角色名称或权限不唯一)

removeRule() 受保护 抽象 方法

从 RBAC 系统中删除规则。

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

要删除的规则

return boolean

是否成功删除了规则

throws Exception

如果数据验证或保存失败(例如规则名称不唯一)

setDefaultRoles() 公共 方法 (自版本 2.0.14 可用)

设置默认角色

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

角色的数组,或者返回角色数组的回调函数

throws yii\base\InvalidArgumentException

当 $roles 既不是数组也不是回调函数

throws yii\base\InvalidValueException

当回调函数返回不是数组时

update() 公共 方法

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() 受保护 抽象 方法

更新 RBAC 系统中的 auth 项。

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

要更新的项目名称

$item yii\rbac\Item

更新的项目

return boolean

是否已成功更新 auth 项

throws Exception

如果数据验证或保存失败(例如角色名称或权限不唯一)

updateRule() 受保护 抽象 方法

更新 RBAC 系统中的规则。

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

要更新的规则的名称

$rule yii\rbac\Rule

更新的规则

return boolean

规则是否已成功更新

throws Exception

如果数据验证或保存失败(例如规则名称不唯一)