PHP Класс yii\mongodb\rbac\MongoDbManager

Manager uses 3 collections for the RBAC data storage: - [[itemCollection]] - stores item data and item parents list - [[assignmentCollection]] - stores assignments info - [[ruleCollection]] - stores rule data These collection are better to be pre-created with search fields indexed.
С версии: 2.0.5
Автор: Paul Klimov ([email protected])
Наследование: extends yii\rbac\BaseManager
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$assignmentCollection the name of the collection 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 MongoDbManager::invalidateCache to ensure data consistency.
$cacheKey the key used to store RBAC data in cache
$db the MongoDB connection object or the application component ID of the MongoDB connection. After the MongoDbManager object is created, if you want to change this property, you should only assign it with a MongoDB connection object.
$itemCollection the name of the collection storing authorization items. Defaults to "auth_item".
$ruleCollection the name of the collection storing rules. Defaults to "auth_rule".

Защищенные свойства (Protected)

Свойство Тип Описание
$items all auth items (name => Item)
$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 ( $roleName )
hasChild ( $parent, $child )
init ( ) Initializes the application component.
invalidateCache ( ) Invalidates RBAC related cache
loadFromCache ( ) Loads data from cache
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.
getItem ( $name )
getItems ( $type )
populateItem ( array $row ) : Item Populates an auth item with the data fetched from collection
removeAllItems ( integer $type ) Removes all auth items of the specified type.
removeItem ( $item )
removeRule ( $rule )
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() публичный Метод

public canAddChild ( $parent, $child )

checkAccess() публичный Метод

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

checkAccessFromCache() защищенный Метод

This method is internally called by MongoDbManager::checkAccess when [[cache]] is enabled.
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 yii\rbac\Assignment[] the assignments to the specified user
Результат boolean whether the operations can be performed by the user.

checkAccessRecursive() защищенный Метод

This method is internally called by MongoDbManager::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 yii\rbac\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 yii\rbac\Item the parent item
$child yii\rbac\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() публичный Метод

С версии: 2.1.2
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)

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() публичный Метод

public getUserIdsByRole ( $roleName )

hasChild() публичный Метод

public hasChild ( $parent, $child )

init() публичный Метод

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

invalidateCache() публичный Метод

Invalidates RBAC related cache
public invalidateCache ( )

loadFromCache() публичный Метод

Loads data from cache
public loadFromCache ( )

populateItem() защищенный Метод

Populates an auth item with the data fetched from collection
protected populateItem ( array $row ) : Item
$row array the data from the auth item collection
Результат yii\rbac\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 )

updateItem() защищенный Метод

protected updateItem ( $name, $item )

updateRule() защищенный Метод

protected updateRule ( $name, $rule )

Описание свойств

$assignmentCollection публичное свойство

the name of the collection storing authorization item assignments. Defaults to "auth_assignment".
public $assignmentCollection

$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 MongoDbManager::invalidateCache to ensure data consistency.
public $cache

$cacheKey публичное свойство

the key used to store RBAC data in cache
См. также: cache
public $cacheKey

$db публичное свойство

the MongoDB connection object or the application component ID of the MongoDB connection. After the MongoDbManager object is created, if you want to change this property, you should only assign it with a MongoDB connection object.
public $db

$itemCollection публичное свойство

the name of the collection storing authorization items. Defaults to "auth_item".
public $itemCollection

$items защищенное свойство

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

$ruleCollection публичное свойство

the name of the collection storing rules. Defaults to "auth_rule".
public $ruleCollection

$rules защищенное свойство

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