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
Exibir arquivo Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property 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

Property Type Description
$assignments array
$children array
$items Item[]
$rules Rule[]

Public Methods

Method 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 )

Protected Methods

Method 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 method

public addChild ( $parent, $child )

addItem() protected method

protected addItem ( $item )

addRule() protected method

protected addRule ( $rule )

assign() public method

public assign ( $role, $userId )

canAddChild() public method

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

checkAccess() public method

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

checkAccessRecursive() protected method

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

detectLoop() protected method

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
return boolean whether a loop exists

getAssignment() public method

public getAssignment ( $roleName, $userId )

getAssignments() public method

public getAssignments ( $userId )

getChildRoles() public method

public getChildRoles ( $roleName )

getChildren() public method

public getChildren ( $name )

getChildrenRecursive() protected method

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 method

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]])
return Permission[] all direct permissions that the user has. The array is indexed by the permission names.

getInheritedPermissionsByUser() protected method

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]])
return Permission[] all inherited permissions that the user has. The array is indexed by the permission names.

getItem() public method

public getItem ( $name )

getItems() public method

public getItems ( $type )

getPermissionsByRole() public method

public getPermissionsByRole ( $roleName )

getPermissionsByUser() public method

public getPermissionsByUser ( $userId )

getRolesByUser() public method

public getRolesByUser ( $userId )

getRule() public method

public getRule ( $name )

getRules() public method

public getRules ( )

getUserIdsByRole() public method

Since: 2.0.7
public getUserIdsByRole ( $roleName )

hasChild() public method

public hasChild ( $parent, $child )

init() public method

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

invalidateScriptCache() protected method

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 method

Loads authorization data from persistent storage.
protected load ( )

loadFromFile() protected method

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

removeAll() public method

public removeAll ( )

removeAllAssignments() public method

removeAllItems() protected method

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 method

removeAllRoles() public method

public removeAllRoles ( )

removeAllRules() public method

public removeAllRules ( )

removeChild() public method

public removeChild ( $parent, $child )

removeChildren() public method

public removeChildren ( $parent )

removeItem() public method

public removeItem ( $item )

removeRule() protected method

protected removeRule ( $rule )

revoke() public method

public revoke ( $role, $userId )

revokeAll() public method

public revokeAll ( $userId )

save() protected method

Saves authorization data into persistent storage.
protected save ( )

saveAssignments() protected method

Saves assignments data into persistent storage.
protected saveAssignments ( )

saveItems() protected method

Saves items data into persistent storage.
protected saveItems ( )

saveRules() protected method

Saves rules data into persistent storage.
protected saveRules ( )

saveToFile() protected method

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 method

protected updateItem ( $name, $item )

updateRule() public method

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
return array

$children protected_oe property

protected array $children
return 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
return 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
return Rule[]