PHP 클래스 yii\rbac\DbManager

The database connection is specified by [[db]]. And the database schema should be as described in "framework/rbac/*.sql". You may change the names of the three tables used to store the authorization data by setting [[itemTable]], [[itemChildTable]] and [[assignmentTable]].
부터: 2.0
저자: Qiang Xue ([email protected])
저자: Alexander Kochetov ([email protected])
상속: extends BaseManager
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$assignmentTable the name of the table storing authorization item assignments. Defaults to "auth_assignment".
$cache the cache used to improve RBAC performance. This can be one of the following: - an application component ID (e.g. cache) - a configuration array - a Cache object When this is not set, it means caching is not enabled. Note that by enabling RBAC cache, all auth items, rules and auth item parent-child relationships will be cached and loaded into memory. This will improve the performance of RBAC permission check. However, it does require extra memory and as a result may not be appropriate if your RBAC system contains too many auth items. You should seek other RBAC implementations (e.g. RBAC based on Redis storage) in this case. Also note that if you modify RBAC items, rules or parent-child relationships from outside of this component, you have to manually call DbManager::invalidateCache to ensure data consistency.
$cacheKey the key used to store RBAC data in cache
$db the DB connection object or the application component ID of the DB connection. After the DbManager object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$itemChildTable the name of the table storing authorization item hierarchy. Defaults to "auth_item_child".
$itemTable the name of the table storing authorization items. Defaults to "auth_item".
$ruleTable the name of the table storing rules. Defaults to "auth_rule".

보호된 프로퍼티들

프로퍼티 타입 설명
$items all auth items (name => Item)
$parents auth item parent-child relationships (childName => list of parents)
$rules all auth rules (name => Rule)

공개 메소드들

메소드 설명
addChild ( $parent, $child )
assign ( $role, $userId )
canAddChild ( $parent, $child )
checkAccess ( $userId, $permissionName, $params = [] )
getAssignment ( $roleName, $userId )
getAssignments ( $userId )
getChildRoles ( $roleName )
getChildren ( $name )
getPermissionsByRole ( $roleName )
getPermissionsByUser ( $userId )
getRolesByUser ( $userId )
getRule ( $name )
getRules ( )
getUserIdsByRole ( string $roleName ) : Assignment[] Returns all role assignment information for the specified role.
hasChild ( $parent, $child )
init ( ) Initializes the application component.
invalidateCache ( )
loadFromCache ( )
removeAll ( )
removeAllAssignments ( )
removeAllPermissions ( )
removeAllRoles ( )
removeAllRules ( )
removeChild ( $parent, $child )
removeChildren ( $parent )
revoke ( $role, $userId )
revokeAll ( $userId )

보호된 메소드들

메소드 설명
addItem ( $item )
addRule ( $rule )
checkAccessFromCache ( string | integer $user, string $itemName, array $params, Assignment[] $assignments ) : boolean Performs access check for the specified user based on the data loaded from cache.
checkAccessRecursive ( string | integer $user, string $itemName, array $params, Assignment[] $assignments ) : boolean Performs access check for the specified user.
detectLoop ( Item $parent, Item $child ) : boolean Checks whether there is a loop in the authorization item hierarchy.
getChildrenList ( ) : array Returns the children for every parent.
getChildrenRecursive ( string $name, array $childrenList, array &$result ) Recursively finds all children and grand children of the specified item.
getDirectPermissionsByUser ( string | integer $userId ) : Permission[] Returns all permissions that are directly assigned to user.
getInheritedPermissionsByUser ( string | integer $userId ) : Permission[] Returns all permissions that the user inherits from the roles assigned to him.
getItem ( $name )
getItems ( $type )
populateItem ( array $row ) : Item Populates an auth item with the data fetched from database
removeAllItems ( integer $type ) Removes all auth items of the specified type.
removeItem ( $item )
removeRule ( $rule )
supportsCascadeUpdate ( ) : boolean Returns a value indicating whether the database supports cascading update and delete.
updateItem ( $name, $item )
updateRule ( $name, $rule )

메소드 상세

addChild() 공개 메소드

public addChild ( $parent, $child )

addItem() 보호된 메소드

protected addItem ( $item )

addRule() 보호된 메소드

protected addRule ( $rule )

assign() 공개 메소드

public assign ( $role, $userId )

canAddChild() 공개 메소드

부터: 2.0.8
public canAddChild ( $parent, $child )

checkAccess() 공개 메소드

public checkAccess ( $userId, $permissionName, $params = [] )

checkAccessFromCache() 보호된 메소드

This method is internally called by DbManager::checkAccess when [[cache]] is enabled.
부터: 2.0.3
protected checkAccessFromCache ( string | integer $user, string $itemName, array $params, Assignment[] $assignments ) : boolean
$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 Assignment[] the assignments to the specified user
리턴 boolean whether the operations can be performed by the user.

checkAccessRecursive() 보호된 메소드

This method is internally called by DbManager::checkAccess.
protected checkAccessRecursive ( string | integer $user, string $itemName, array $params, Assignment[] $assignments ) : boolean
$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 Assignment[] the assignments to the specified user
리턴 boolean whether the operations can be performed by the user.

detectLoop() 보호된 메소드

Checks whether there is a loop in the authorization item hierarchy.
protected detectLoop ( Item $parent, Item $child ) : boolean
$parent Item the parent item
$child Item the child item to be added to the hierarchy
리턴 boolean whether a loop exists

getAssignment() 공개 메소드

public getAssignment ( $roleName, $userId )

getAssignments() 공개 메소드

public getAssignments ( $userId )

getChildRoles() 공개 메소드

public getChildRoles ( $roleName )

getChildren() 공개 메소드

public getChildren ( $name )

getChildrenList() 보호된 메소드

Returns the children for every parent.
protected getChildrenList ( ) : array
리턴 array the children list. Each array key is a parent item name, and the corresponding array value is a list of child item names.

getChildrenRecursive() 보호된 메소드

Recursively finds all children and grand children of the specified item.
protected getChildrenRecursive ( string $name, array $childrenList, array &$result )
$name string the name of the item whose children are to be looked for.
$childrenList array the child list built via [[getChildrenList()]]
$result array the children and grand children (in array keys)

getDirectPermissionsByUser() 보호된 메소드

Returns all permissions that are directly assigned to user.
부터: 2.0.7
protected getDirectPermissionsByUser ( string | integer $userId ) : Permission[]
$userId string | integer the user ID (see [[\yii\web\User::id]])
리턴 Permission[] all direct permissions that the user has. The array is indexed by the permission names.

getInheritedPermissionsByUser() 보호된 메소드

Returns all permissions that the user inherits from the roles assigned to him.
부터: 2.0.7
protected getInheritedPermissionsByUser ( string | integer $userId ) : Permission[]
$userId string | integer the user ID (see [[\yii\web\User::id]])
리턴 Permission[] all inherited permissions that the user has. The array is indexed by the permission names.

getItem() 보호된 메소드

protected getItem ( $name )

getItems() 보호된 메소드

protected getItems ( $type )

getPermissionsByRole() 공개 메소드

public getPermissionsByRole ( $roleName )

getPermissionsByUser() 공개 메소드

public getPermissionsByUser ( $userId )

getRolesByUser() 공개 메소드

public getRolesByUser ( $userId )

getRule() 공개 메소드

public getRule ( $name )

getRules() 공개 메소드

public getRules ( )

getUserIdsByRole() 공개 메소드

Returns all role assignment information for the specified role.
부터: 2.0.7
public getUserIdsByRole ( string $roleName ) : Assignment[]
$roleName string
리턴 Assignment[] the assignments. An empty array will be returned if role is not assigned to any user.

hasChild() 공개 메소드

public hasChild ( $parent, $child )

init() 공개 메소드

This method overrides the parent implementation by establishing the database connection.
public init ( )

invalidateCache() 공개 메소드

public invalidateCache ( )

loadFromCache() 공개 메소드

public loadFromCache ( )

populateItem() 보호된 메소드

Populates an auth item with the data fetched from database
protected populateItem ( array $row ) : Item
$row array the data from the auth item table
리턴 Item the populated auth item instance (either Role or Permission)

removeAll() 공개 메소드

public removeAll ( )

removeAllAssignments() 공개 메소드

removeAllItems() 보호된 메소드

Removes all auth items of the specified type.
protected removeAllItems ( integer $type )
$type integer the auth item type (either Item::TYPE_PERMISSION or Item::TYPE_ROLE)

removeAllPermissions() 공개 메소드

removeAllRoles() 공개 메소드

public removeAllRoles ( )

removeAllRules() 공개 메소드

public removeAllRules ( )

removeChild() 공개 메소드

public removeChild ( $parent, $child )

removeChildren() 공개 메소드

public removeChildren ( $parent )

removeItem() 보호된 메소드

protected removeItem ( $item )

removeRule() 보호된 메소드

protected removeRule ( $rule )

revoke() 공개 메소드

public revoke ( $role, $userId )

revokeAll() 공개 메소드

public revokeAll ( $userId )

supportsCascadeUpdate() 보호된 메소드

The default implementation will return false for SQLite database and true for all other databases.
protected supportsCascadeUpdate ( ) : boolean
리턴 boolean whether the database supports cascading update and delete.

updateItem() 보호된 메소드

protected updateItem ( $name, $item )

updateRule() 보호된 메소드

protected updateRule ( $name, $rule )

프로퍼티 상세

$assignmentTable 공개적으로 프로퍼티

the name of the table storing authorization item assignments. Defaults to "auth_assignment".
public $assignmentTable

$cache 공개적으로 프로퍼티

the cache used to improve RBAC performance. This can be one of the following: - an application component ID (e.g. cache) - a configuration array - a Cache object When this is not set, it means caching is not enabled. Note that by enabling RBAC cache, all auth items, rules and auth item parent-child relationships will be cached and loaded into memory. This will improve the performance of RBAC permission check. However, it does require extra memory and as a result may not be appropriate if your RBAC system contains too many auth items. You should seek other RBAC implementations (e.g. RBAC based on Redis storage) in this case. Also note that if you modify RBAC items, rules or parent-child relationships from outside of this component, you have to manually call DbManager::invalidateCache to ensure data consistency.
부터: 2.0.3
public $cache

$cacheKey 공개적으로 프로퍼티

the key used to store RBAC data in cache
또한 보기: cache
부터: 2.0.3
public $cacheKey

$db 공개적으로 프로퍼티

the DB connection object or the application component ID of the DB connection. After the DbManager object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $db

$itemChildTable 공개적으로 프로퍼티

the name of the table storing authorization item hierarchy. Defaults to "auth_item_child".
public $itemChildTable

$itemTable 공개적으로 프로퍼티

the name of the table storing authorization items. Defaults to "auth_item".
public $itemTable

$items 보호되어 있는 프로퍼티

all auth items (name => Item)
protected $items

$parents 보호되어 있는 프로퍼티

auth item parent-child relationships (childName => list of parents)
protected $parents

$ruleTable 공개적으로 프로퍼티

the name of the table storing rules. Defaults to "auth_rule".
public $ruleTable

$rules 보호되어 있는 프로퍼티

all auth rules (name => Rule)
protected $rules