PHP Class Vanilla\Permissions

Exibir arquivo Open project: vanilla/vanilla

Public Methods

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

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

add() public method

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 method

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 method

Grab the current permissions.
public getPermissions ( ) : array
return array

has() public method

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)
return boolean

hasAll() public method

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)
return boolean

hasAny() public method

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)
return boolean

isAdmin() public method

Determine if the admin flag is set.
public isAdmin ( ) : boolean
return boolean

isBanned() public method

Determine if the banned flag is set.
public isBanned ( ) : boolean
return boolean

merge() public method

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

overwrite() public method

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 method

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 method

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 method

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

setBanned() public method

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

setPermissions() public method

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