PHP Класс yii\rbac\PhpManager

The authorization data will be saved to and loaded from a file specified by [[authFile]], which defaults to 'protected/data/rbac.php'. PhpManager is mainly suitable for authorization data that is not too big (for example, the authorization data for a personal blog system). Use DbManager for more complex authorization data.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Автор: Alexander Kochetov ([email protected])
Наследование: extends yii\rbac\Manager
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$assignmentFile the path of the PHP script that contains the authorization assignments. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.
$itemFile the path of the PHP script that contains the authorization items. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.
$ruleFile the path of the PHP script that contains the authorization rules. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.

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

Свойство Тип Описание
$assignments array
$children array
$items Item[]
$rules Rule[]

Открытые методы

Метод Описание
addChild ( $parent, $child )
assign ( $role, $userId )
canAddChild ( $parent, $child )
checkAccess ( $userId, $permissionName, $params = [] )
getAssignment ( $roleName, $userId )
getAssignments ( $userId )
getChildRoles ( $roleName )
getChildren ( $name )
getItem ( $name )
getItems ( $type )
getPermissionsByRole ( $roleName )
getPermissionsByUser ( $userId )
getRolesByUser ( $userId )
getRule ( $name )
getRules ( )
getUserIdsByRole ( $roleName )
hasChild ( $parent, $child )
init ( ) Initializes the application component.
removeAll ( )
removeAllAssignments ( )
removeAllPermissions ( )
removeAllRoles ( )
removeAllRules ( )
removeChild ( $parent, $child )
removeChildren ( $parent )
removeItem ( $item )
revoke ( $role, $userId )
revokeAll ( $userId )
updateRule ( $name, $rule )

Защищенные методы

Метод Описание
addItem ( $item )
addRule ( $rule )
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.
getChildrenRecursive ( string $name, 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.
invalidateScriptCache ( string $file ) Invalidates precompiled script cache (such as OPCache or APC) for the given file.
load ( ) Loads authorization data from persistent storage.
loadFromFile ( string $file ) : array Loads the authorization data from a PHP script file.
removeAllItems ( integer $type ) Removes all auth items of the specified type.
removeRule ( $rule )
save ( ) Saves authorization data into persistent storage.
saveAssignments ( ) Saves assignments data into persistent storage.
saveItems ( ) Saves items data into persistent storage.
saveRules ( ) Saves rules data into persistent storage.
saveToFile ( array $data, string $file ) Saves the authorization data to a PHP script file.
updateItem ( $name, $item )

Описание методов

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 = [] )

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

This method is internally called by PhpManager::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 parent item
$child Item the child item that is 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 )

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

Recursively finds all children and grand children of the specified item.
protected getChildrenRecursive ( string $name, array &$result )
$name string the name of the item whose children are to be looked for.
$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() публичный Метод

public getItem ( $name )

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

public getItems ( $type )

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

public getPermissionsByRole ( $roleName )

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

public getPermissionsByUser ( $userId )

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

public getRolesByUser ( $userId )

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

public getRule ( $name )

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

public getRules ( )

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

С версии: 2.0.7
public getUserIdsByRole ( $roleName )

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

public hasChild ( $parent, $child )

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

This method overrides parent implementation by loading the authorization data from PHP script.
public init ( )

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

Invalidates precompiled script cache (such as OPCache or APC) for the given file.
С версии: 2.0.9
protected invalidateScriptCache ( string $file )
$file string the file path.

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

Loads authorization data from persistent storage.
protected load ( )

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

Loads the authorization data from a PHP script file.
См. также: saveToFile()
protected loadFromFile ( string $file ) : array
$file string the file path.
Результат array the authorization data

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

public removeItem ( $item )

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

protected removeRule ( $rule )

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

public revoke ( $role, $userId )

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

public revokeAll ( $userId )

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

Saves authorization data into persistent storage.
protected save ( )

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

Saves assignments data into persistent storage.
protected saveAssignments ( )

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

Saves items data into persistent storage.
protected saveItems ( )

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

Saves rules data into persistent storage.
protected saveRules ( )

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

Saves the authorization data to a PHP script file.
См. также: loadFromFile()
protected saveToFile ( array $data, string $file )
$data array the authorization data
$file string the file path.

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

protected updateItem ( $name, $item )

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

public updateRule ( $name, $rule )

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

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

the path of the PHP script that contains the authorization assignments. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.
См. также: loadFromFile()
См. также: saveToFile()
public $assignmentFile

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

protected array $assignments
Результат array

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

protected array $children
Результат array

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

the path of the PHP script that contains the authorization items. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.
См. также: loadFromFile()
См. также: saveToFile()
public $itemFile

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

protected Item[],yii\rbac $items
Результат Item[]

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

the path of the PHP script that contains the authorization rules. This can be either a file path or a path alias to the file. Make sure this file is writable by the Web server process if the authorization needs to be changed online.
См. также: loadFromFile()
См. также: saveToFile()
public $ruleFile

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

protected Rule[],yii\rbac $rules
Результат Rule[]