0 follower

Abstract Class yii\rbac\BaseManager

Inheritanceyii\rbac\BaseManager » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable, yii\rbac\ManagerInterface
Subclassesyii\rbac\DbManager, yii\rbac\PhpManager
Available since version2.0
Source Code 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.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$defaultRoleInstances yii\rbac\Role[] Default roles. yii\rbac\BaseManager
$permissions yii\rbac\BaseManager
$roles yii\rbac\BaseManager
$rules yii\rbac\Rule[] The rules indexed by the rule names yii\rbac\ManagerInterface

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$defaultRoles array A list of role names that are assigned to every user automatically without calling assign(). yii\rbac\BaseManager

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__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() {@inheritdoc} 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() {@inheritdoc} yii\rbac\BaseManager
createRole() {@inheritdoc} 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() Returns defaultRoles as array of Role objects. yii\rbac\BaseManager
getDefaultRoles() Get default roles yii\rbac\BaseManager
getPermission() {@inheritdoc} yii\rbac\BaseManager
getPermissions() {@inheritdoc} 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() {@inheritdoc} yii\rbac\BaseManager
getRoles() {@inheritdoc} 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() {@inheritdoc} 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() Triggers an event. yii\base\Component
update() {@inheritdoc} yii\rbac\BaseManager

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
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

Property Details

$defaultRoleInstances public read-only property

Default roles. The array is indexed by the role names

$defaultRoles protected property

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.

public string[] getDefaultRoles ( )
public void setDefaultRoles ( $roles )
$permissions public read-only property
public void getPermissions ( )
$roles public read-only property
public void getRoles ( )

Method Details

add() public method

{@inheritdoc}

public void add ( $object )
$object
addItem() protected abstract method

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 method

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 method

{@inheritdoc}

public void createPermission ( $name )
$name
createRole() public method

{@inheritdoc}

public void createRole ( $name )
$name
executeRule() protected method

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 method (available since version 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 method (available since version 2.0.14)

Get default roles

public string[] getDefaultRoles ( )
return string[]

Default roles

getItem() protected abstract method

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 method

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 method

{@inheritdoc}

public void getPermission ( $name )
$name
getPermissions() public method

{@inheritdoc}

public void getPermissions ( )
getRole() public method

{@inheritdoc}

public void getRole ( $name )
$name
getRoles() public method

{@inheritdoc}

public void getRoles ( )
hasNoAssignments() protected method (available since version 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 method

{@inheritdoc}

public void remove ( $object )
$object
removeItem() protected abstract method

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 method

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 method (available since version 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 method

{@inheritdoc}

public void update ( $name, $object )
$name
$object
updateItem() protected abstract method

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 method

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)