PHP Class Vanilla\Permissions

Afficher le fichier Open project: vanilla/vanilla

Méthodes publiques

Méthode Description
__construct ( array $permissions = [] ) Permissions constructor.
add ( string $permission, integer | array $IDs ) Add a permission.
compileAndLoad ( array $permissions ) Compile raw permission rows into a formatted array of granted permissions.
getPermissions ( ) : array Grab the current permissions.
has ( string $permission, integer | null $id = null ) : boolean Determine if the permission is present.
hasAll ( array $permissions, integer | null $id = null ) : boolean Determine if all of the provided permissions are present.
hasAny ( array $permissions, integer | null $id = null ) : boolean Determine if any of the provided permissions are present.
isAdmin ( ) : boolean Determine if the admin flag is set.
isBanned ( ) : boolean Determine if the banned flag is set.
merge ( Permissions $source ) Merge in data from another Permissions instance.
overwrite ( string $permission, boolean | array $value ) Set global or replace per-ID permissions.
remove ( $permission, integer | array $IDs ) Remove a permission.
set ( string $permission, boolean $value ) Add a global permission.
setAdmin ( boolean $isAdmin ) Set the admin flag.
setBanned ( boolean $isBanned ) Set the banned flag.
setPermissions ( array $permissions ) Set the permission array.

Method Details

__construct() public méthode

Permissions constructor.
public __construct ( array $permissions = [] )
$permissions array

add() public méthode

Add a permission.
public add ( string $permission, integer | array $IDs )
$permission string Permission slug to set the value for (e.g. Vanilla.Discussions.View)
$IDs integer | array One or more IDs of foreign objects (e.g. category IDs)

compileAndLoad() public méthode

Compile raw permission rows into a formatted array of granted permissions.
public compileAndLoad ( array $permissions )
$permissions array Rows from the Permissions database table.

getPermissions() public méthode

Grab the current permissions.
public getPermissions ( ) : array
Résultat array

has() public méthode

Determine if the permission is present.
public has ( string $permission, integer | null $id = null ) : boolean
$permission string Permission slug to check the value for (e.g. Vanilla.Discussions.View)
$id integer | null Foreign object ID to validate the permission against (e.g. a category ID)
Résultat boolean

hasAll() public méthode

Determine if all of the provided permissions are present.
public hasAll ( array $permissions, integer | null $id = null ) : boolean
$permissions array Permission slugs to check the value for (e.g. Vanilla.Discussions.View)
$id integer | null Foreign object ID to validate the permissions against (e.g. a category ID)
Résultat boolean

hasAny() public méthode

Determine if any of the provided permissions are present.
public hasAny ( array $permissions, integer | null $id = null ) : boolean
$permissions array Permission slugs to check the value for (e.g. Vanilla.Discussions.View)
$id integer | null Foreign object ID to validate the permissions against (e.g. a category ID)
Résultat boolean

isAdmin() public méthode

Determine if the admin flag is set.
public isAdmin ( ) : boolean
Résultat boolean

isBanned() public méthode

Determine if the banned flag is set.
public isBanned ( ) : boolean
Résultat boolean

merge() public méthode

Merge in data from another Permissions instance.
public merge ( Permissions $source )
$source Permissions The source Permissions instance to import permissions from.

overwrite() public méthode

Set global or replace per-ID permissions.
public overwrite ( string $permission, boolean | array $value )
$permission string Permission slug to set the value for (e.g. Vanilla.Discussions.View)
$value boolean | array A single value for global permissions or an array of foreign object IDs for per-ID permissions.

remove() public méthode

Remove a permission.
public remove ( $permission, integer | array $IDs )
$permission Permission slug to set the value for (e.g. Vanilla.Discussions.View)
$IDs integer | array One or more IDs of foreign objects (e.g. category IDs)

set() public méthode

Add a global permission.
public set ( string $permission, boolean $value )
$permission string Permission slug to set the value for (e.g. Vanilla.Discussions.View)
$value boolean Toggle value for the permission: true for granted, false for revoked.

setAdmin() public méthode

Set the admin flag.
public setAdmin ( boolean $isAdmin )
$isAdmin boolean Is the user an administrator?

setBanned() public méthode

Set the banned flag.
public setBanned ( boolean $isBanned )
$isBanned boolean Is the user banned?

setPermissions() public méthode

Set the permission array.
public setPermissions ( array $permissions )
$permissions array A properly-formatted permissions array.