PHP Class 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.
Since: 2.0
Author: Qiang Xue ([email protected])
Author: Alexander Kochetov ([email protected])
Inheritance: extends yii\rbac\Manager
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$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 Properties

Свойство Type Description
$assignments array
$children array
$items Item[]
$rules Rule[]

Méthodes publiques

Méthode Description
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 )

Méthodes protégées

Méthode Description
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 )

Method Details

addChild() public méthode

public addChild ( $parent, $child )

addItem() protected méthode

protected addItem ( $item )

addRule() protected méthode

protected addRule ( $rule )

assign() public méthode

public assign ( $role, $userId )

canAddChild() public méthode

Since: 2.0.8
public canAddChild ( $parent, $child )

checkAccess() public méthode

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

checkAccessRecursive() protected méthode

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
Résultat boolean whether the operations can be performed by the user.

detectLoop() protected méthode

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
Résultat boolean whether a loop exists

getAssignment() public méthode

public getAssignment ( $roleName, $userId )

getAssignments() public méthode

public getAssignments ( $userId )

getChildRoles() public méthode

public getChildRoles ( $roleName )

getChildren() public méthode

public getChildren ( $name )

getChildrenRecursive() protected méthode

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() protected méthode

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

getInheritedPermissionsByUser() protected méthode

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

getItem() public méthode

public getItem ( $name )

getItems() public méthode

public getItems ( $type )

getPermissionsByRole() public méthode

public getPermissionsByRole ( $roleName )

getPermissionsByUser() public méthode

public getPermissionsByUser ( $userId )

getRolesByUser() public méthode

public getRolesByUser ( $userId )

getRule() public méthode

public getRule ( $name )

getRules() public méthode

public getRules ( )

getUserIdsByRole() public méthode

Since: 2.0.7
public getUserIdsByRole ( $roleName )

hasChild() public méthode

public hasChild ( $parent, $child )

init() public méthode

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

invalidateScriptCache() protected méthode

Invalidates precompiled script cache (such as OPCache or APC) for the given file.
Since: 2.0.9
protected invalidateScriptCache ( string $file )
$file string the file path.

load() protected méthode

Loads authorization data from persistent storage.
protected load ( )

loadFromFile() protected méthode

Loads the authorization data from a PHP script file.
See also: saveToFile()
protected loadFromFile ( string $file ) : array
$file string the file path.
Résultat array the authorization data

removeAll() public méthode

public removeAll ( )

removeAllAssignments() public méthode

removeAllItems() protected méthode

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() public méthode

removeAllRoles() public méthode

public removeAllRoles ( )

removeAllRules() public méthode

public removeAllRules ( )

removeChild() public méthode

public removeChild ( $parent, $child )

removeChildren() public méthode

public removeChildren ( $parent )

removeItem() public méthode

public removeItem ( $item )

removeRule() protected méthode

protected removeRule ( $rule )

revoke() public méthode

public revoke ( $role, $userId )

revokeAll() public méthode

public revokeAll ( $userId )

save() protected méthode

Saves authorization data into persistent storage.
protected save ( )

saveAssignments() protected méthode

Saves assignments data into persistent storage.
protected saveAssignments ( )

saveItems() protected méthode

Saves items data into persistent storage.
protected saveItems ( )

saveRules() protected méthode

Saves rules data into persistent storage.
protected saveRules ( )

saveToFile() protected méthode

Saves the authorization data to a PHP script file.
See also: loadFromFile()
protected saveToFile ( array $data, string $file )
$data array the authorization data
$file string the file path.

updateItem() protected méthode

protected updateItem ( $name, $item )

updateRule() public méthode

public updateRule ( $name, $rule )

Property Details

$assignmentFile public_oe property

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.
See also: loadFromFile()
See also: saveToFile()
public $assignmentFile

$assignments protected_oe property

protected array $assignments
Résultat array

$children protected_oe property

protected array $children
Résultat array

$itemFile public_oe property

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.
See also: loadFromFile()
See also: saveToFile()
public $itemFile

$items protected_oe property

protected Item[],yii\rbac $items
Résultat Item[]

$ruleFile public_oe property

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.
See also: loadFromFile()
See also: saveToFile()
public $ruleFile

$rules protected_oe property

protected Rule[],yii\rbac $rules
Résultat Rule[]