Class mdm\admin\components\DbManager

Inheritancemdm\admin\components\DbManager » yii\rbac\DbManager » yii\rbac\BaseManager » yii\base\Component » yii\base\Object
Implementsyii\rbac\ManagerInterface
Available since version1.0

DbManager represents an authorization manager that stores authorization information in database.

The database connection is specified by $db. The database schema could be initialized by applying migration:

yii migrate --migrationPath=@yii/rbac/migrations/

If you don't want to use migration and need SQL instead, files for all databases are in migrations directory.

You may change the names of the three tables used to store the authorization data by setting yii\rbac\DbManager::$itemTable, yii\rbac\DbManager::$itemChildTable and yii\rbac\DbManager::$assignmentTable.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$assignmentTable string The name of the table storing authorization item assignments. yii\rbac\DbManager
$behaviors yii\base\Behavior[] List of behaviors attached to this component mdm\admin\components\DbManager
$cache string|yii\caching\Cache Cache component mdm\admin\components\DbManager
$cacheDuration integer Cache duration mdm\admin\components\DbManager
$db yii\db\Connection|string The DB connection object or the application component ID of the DB connection. yii\rbac\DbManager
$defaultRoles array A list of role names that are assigned to every user automatically without calling assign(). yii\rbac\BaseManager
$enableCaching boolean Enable caching mdm\admin\components\DbManager
$itemChildTable string The name of the table storing authorization item hierarchy. yii\rbac\DbManager
$itemTable string The name of the table storing authorization items. yii\rbac\DbManager
$permissions yii\rbac\Permission[] All permissions in the system. mdm\admin\components\DbManager
$roles yii\rbac\Role[] All roles in the system. mdm\admin\components\DbManager
$ruleTable string The name of the table storing rules. yii\rbac\DbManager
$rules yii\rbac\Rule[] The rules indexed by the rule names mdm\admin\components\DbManager

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\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property value is 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. mdm\admin\components\DbManager
assign() Assigns a role to a user. mdm\admin\components\DbManager
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
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
checkAccess() Checks if the user has the specified permission. mdm\admin\components\DbManager
className() Returns the fully qualified name of this class. yii\base\Object
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. mdm\admin\components\DbManager
getAssignments() Returns all role assignment information for the specified user. mdm\admin\components\DbManager
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getChildren() Returns the child permissions and/or roles. mdm\admin\components\DbManager
getItem() Returns the named auth item. mdm\admin\components\DbManager
getItems() Returns the items of the specified type. mdm\admin\components\DbManager
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. mdm\admin\components\DbManager
getPermissionsByUser() Returns all permissions that the user has. mdm\admin\components\DbManager
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(). mdm\admin\components\DbManager
getRule() Returns the rule of the specified name. mdm\admin\components\DbManager
getRules() Returns all rules available in the system. mdm\admin\components\DbManager
hasChild() Returns a value indicating whether the child already exists for the parent. mdm\admin\components\DbManager
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 application component. mdm\admin\components\DbManager
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. mdm\admin\components\DbManager
removeAllAssignments() Removes all role assignments. mdm\admin\components\DbManager
removeAllPermissions() Removes all permissions. yii\rbac\ManagerInterface
removeAllRoles() Removes all roles. yii\rbac\ManagerInterface
removeAllRules() Removes all rules. mdm\admin\components\DbManager
removeChild() Removes a child from its parent. mdm\admin\components\DbManager
removeChildren() Removed all children form their parent. mdm\admin\components\DbManager
removeItem() Removes an auth item from the RBAC system. mdm\admin\components\DbManager
revoke() Revokes a role from a user. mdm\admin\components\DbManager
revokeAll() Revokes all roles from a user. mdm\admin\components\DbManager
trigger() Triggers an event. yii\base\Component
update() Updates the specified role, permission or rule in the system. yii\rbac\BaseManager
updateRule() Updates a rule to the RBAC system. mdm\admin\components\DbManager

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addItem() Adds an auth item to the RBAC system. mdm\admin\components\DbManager
addRule() Adds a rule to the RBAC system. mdm\admin\components\DbManager
checkAccessRecursive() Performs access check for the specified user. mdm\admin\components\DbManager
detectLoop() Checks whether there is a loop in the authorization item hierarchy. yii\rbac\DbManager
executeRule() Executes the rule associated with the specified auth item. yii\rbac\BaseManager
getChildrenList() Returns the children for every parent. mdm\admin\components\DbManager
getChildrenRecursive() Recursively finds all children and grand children of the specified item. yii\rbac\DbManager
populateItem() Populates an auth item with the data fetched from database yii\rbac\DbManager
removeAllItems() Removes all auth items of the specified type. mdm\admin\components\DbManager
removeRule() Removes a rule from the RBAC system. mdm\admin\components\DbManager
supportsCascadeUpdate() Returns a value indicating whether the database supports cascading update and delete. yii\rbac\DbManager
updateItem() Updates an auth item in the RBAC system. mdm\admin\components\DbManager

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
PART_CHILDREN 'mdm.admin.children' mdm\admin\components\DbManager
PART_ITEMS 'mdm.admin.items' mdm\admin\components\DbManager
PART_RULES 'mdm.admin.rules' mdm\admin\components\DbManager

Property Details

$behaviors public read-only property

List of behaviors attached to this component

$cache public property

Cache component

$cacheDuration public property

Cache duration

$enableCaching public property

Enable caching

$permissions public read-only property

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

$roles public read-only property

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

$rules public read-only property

The rules indexed by the rule names

Method Details

addChild() public method

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.

addItem() protected method

Adds an auth item to the RBAC system.

boolean addItem$item )
$item yii\rbac\Item
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 method

Adds a rule to the RBAC system.

boolean addRule$rule )
$rule yii\rbac\Rule
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)

assign() public method

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

checkAccess() public method

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

checkAccessRecursive() protected method

Performs access check for the specified user.

This method is internally called by checkAccess().

boolean checkAccessRecursive$user$itemName$params$assignments )
$user string|integer

The user ID. This should can be either an integer or a string representing the unique identifier of a user. See yii\web\User::$id.

$itemName string

The name of the operation that need access check

$params array

Name-value pairs that would be passed to rules associated with the tasks and roles assigned to the user. A param with name 'user' is added to this array, which holds the value of $userId.

$assignments yii\rbac\Assignment[]

The assignments to the specified user

return boolean

Whether the operations can be performed by the user.

getAssignment() public method

Returns the assignment information regarding a role and a user.

yii\rbac\Assignment getAssignment$roleName$userId )
$roleName string

The role name

$userId string|integer

The user ID (see yii\web\User::$id)

return yii\rbac\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.

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.

getChildren() public method

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

getChildrenList() protected method

Returns the children for every parent.

array getChildrenList( )
return array

The children list. Each array key is a parent item name, and the corresponding array value is a list of child item names.

getItem() public method

Returns the named auth item.

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

Returns the items of the specified type.

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.

getPermissionsByRole() public method

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.

getPermissionsByUser() public method

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.

getRolesByUser() public method

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.

getRule() public method

Returns the rule of the specified name.

yii\rbac\Rule getRule$name )
$name string

The rule name

return yii\rbac\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.

yii\rbac\Rule[] getRules( )
return yii\rbac\Rule[]

The rules indexed by the rule names

hasChild() public method

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 $child is already a child of $parent

init() public method

Initializes the application component.

This method overrides the parent implementation by establishing the database connection.

void init( )
removeAll() public method

Removes all authorization data, including roles, permissions, rules, and assignments.

void removeAll( )
removeAllAssignments() public method

Removes all role assignments.

void removeAllAssignments( )
removeAllItems() protected method

Removes all auth items of the specified type.

void removeAllItems$type )
$type integer

The auth item type (either Item::TYPE_PERMISSION or Item::TYPE_ROLE)

removeAllRules() public method

Removes all rules.

All roles and permissions which have rules will be adjusted accordingly.

void removeAllRules( )
removeChild() public method

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

removeChildren() public method

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

removeItem() public method

Removes an auth item from the RBAC system.

boolean removeItem$item )
$item yii\rbac\Item
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 method

Removes a rule from the RBAC system.

boolean removeRule$rule )
$rule yii\rbac\Rule
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)

revoke() public method

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

revokeAll() public method

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

updateItem() protected method

Updates an auth item in the RBAC system.

boolean updateItem$name$item )
$name string

The old name of the auth item

$item yii\rbac\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() public method

Updates a rule to the RBAC system.

boolean updateRule$name$rule )
$name string

The old name of the rule

$rule yii\rbac\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)