PHP Класс Habari\ACL

The default Habari ACL class implements groups, and group permissions Users are assigned to one or more groups. Groups are assigned one or more permissions. Membership in any group that grants a permission means you have that permission. Membership in any group that denies that permission denies the user that permission, even if another group grants that permission.
Показать файл Открыть проект

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

Метод Описание
__static ( ) Register plugin hooks
_filter_permission_display ( $permission ) : string function _filter_permission_display Filter to localize permission names
_filter_token_description_display ( $token ) : string function _filter_token_description_display Filter to localize token descriptions
_filter_token_group_display ( $group ) : string function _filter_token_group_display Filter to localize token group name
access_check ( Bitmask $bitmask, mixed $access ) : boolean Check a permission bitmask for a particular access type.
access_names ( ) : array Obtain the list of access names (CRUD) to use for permissions.
all_tokens ( string $order = 'id' ) : array Get an array of QueryRecord objects containing all permission tokens
clear_caches ( ) Clears all caches used to hold permissions
create_default_tokens ( ) Creates the default set of permissions.
create_token ( string $name, string $description, string $group, boolean $crud = false ) : mixed Create a new permission token, and save it to the permission tokens table
deny_group ( integer $group_id, mixed $token_id ) : Result Deny permission to a group
deny_user ( integer $user_id, mixed $token_id ) : Result Deny permission to a user
destroy_token ( $token ) : boolean Remove a permission token, and any assignments of it
get_bitmask ( integer $mask ) : Bitmask Get a Bitmask object representing the supplied access integer
get_group_token_access ( integer $group, mixed $token_id ) : an Get the access bitmask of a group for a specific permission token
get_user_token_access ( User | integer $user, string | integer $token ) : Bitmask Return the access bitmask to a specific token for a specific user
grant_group ( integer $group_id, mixed $token_id, string $access = 'full' ) : Result Grant a permission to a group
grant_user ( integer $user_id, integer $token_id, string $access = 'full' ) : Result Grant a permission to a user
group_can ( mixed $group, mixed $token_id, string $access = 'full' ) : boolean Determine whether a group can perform a specific action
group_cannot ( $group, mixed $token_id ) : boolean Determine whether a group is explicitly denied permission to perform a specific action This function does not return true if the group is merely not granted a permission
normalize_token ( string $name ) : string Convert a token name into a valid format
rebuild_permissions ( $user = null ) Reset premissions to their default state
revoke_group_token ( integer $group_id, mixed $token_id ) : the Remove a permission token from the group permissions table
revoke_user_token ( integer $user_id, mixed $token_id ) : the Remove a permission token from the user permissions table
token_description ( mixed $permission ) : string Fetch a permission token's description from the DB
token_exists ( mixed $permission ) : boolean Determine whether a permission token exists
token_id ( string $name ) : integer Get a permission token's ID by its name
token_name ( integer $id ) : string Get a permission token's name by its ID
user_can ( mixed $user, mixed $token_id, string $access = 'full' ) : boolean Determine whether a user can perform a specific action
user_cannot ( mixed $user, mixed $token_id ) : boolean Determine whether a user is explicitly denied permission to perform a specific action This function does not return true if the user is merely not granted a permission
user_tokens ( mixed $user, string $access = 'full', $posts_only = false ) : array Get all the tokens for a given user with a particular kind of access

Приватные методы

Метод Описание
cache_tokens ( ) : array Get an associative array of token ids and their name.

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

__static() публичный статический Метод

Register plugin hooks
public static __static ( )

_filter_permission_display() публичный статический Метод

function _filter_permission_display Filter to localize permission names
public static _filter_permission_display ( $permission ) : string
Результат string The localized permission name

_filter_token_description_display() публичный статический Метод

function _filter_token_description_display Filter to localize token descriptions
public static _filter_token_description_display ( $token ) : string
Результат string The localized token description

_filter_token_group_display() публичный статический Метод

function _filter_token_group_display Filter to localize token group name
public static _filter_token_group_display ( $group ) : string
Результат string The localized token group name

access_check() публичный статический Метод

Check a permission bitmask for a particular access type.
public static access_check ( Bitmask $bitmask, mixed $access ) : boolean
$bitmask Bitmask The permission bitmask
$access mixed The name of the access to check against (read, write, full)
Результат boolean Returns true if the given access meets exceeds the access to check against

access_names() публичный статический Метод

Obtain the list of access names (CRUD) to use for permissions.
public static access_names ( ) : array
Результат array the list of access names available to ACL

all_tokens() публичный статический Метод

Get an array of QueryRecord objects containing all permission tokens
public static all_tokens ( string $order = 'id' ) : array
$order string the order in which to sort the returning array
Результат array an array of QueryRecord objects containing all tokens

clear_caches() публичный статический Метод

Clears all caches used to hold permissions
public static clear_caches ( )

create_default_tokens() публичный статический Метод

Creates the default set of permissions.
public static create_default_tokens ( )

create_token() публичный статический Метод

Create a new permission token, and save it to the permission tokens table
public static create_token ( string $name, string $description, string $group, boolean $crud = false ) : mixed
$name string The name of the permission
$description string The description of the permission
$group string The token group for organizational purposes
$crud boolean Indicates if the token is a CRUD or boolean type token (default is boolean)
Результат mixed the ID of the newly created permission, or boolean false

deny_group() публичный статический Метод

Deny permission to a group
public static deny_group ( integer $group_id, mixed $token_id ) : Result
$group_id integer The group ID
$token_id mixed The name or ID of the permission token
Результат Result of the DB query

deny_user() публичный статический Метод

Deny permission to a user
public static deny_user ( integer $user_id, mixed $token_id ) : Result
$user_id integer The user ID
$token_id mixed The name or ID of the permission token
Результат Result of the DB query

destroy_token() публичный статический Метод

Remove a permission token, and any assignments of it
public static destroy_token ( $token ) : boolean
Результат boolean whether the permission was deleted or not

get_bitmask() публичный статический Метод

Get a Bitmask object representing the supplied access integer
public static get_bitmask ( integer $mask ) : Bitmask
$mask integer The access mask, usually stored in the database
Результат Bitmask An object representing the access value

get_group_token_access() публичный статический Метод

Get the access bitmask of a group for a specific permission token
public static get_group_token_access ( integer $group, mixed $token_id ) : an
$group integer The group ID
$token_id mixed A permission name or ID
Результат an access bitmask

get_user_token_access() публичный статический Метод

Return the access bitmask to a specific token for a specific user
public static get_user_token_access ( User | integer $user, string | integer $token ) : Bitmask
$user User | integer A User object instance or user id
$token string | integer A permission token name or token ID
Результат Bitmask An access bitmask

grant_group() публичный статический Метод

Grant a permission to a group
public static grant_group ( integer $group_id, mixed $token_id, string $access = 'full' ) : Result
$group_id integer The group ID
$token_id mixed The name or ID of the permission token to grant
$access string The kind of access to assign the group
Результат Result of the DB query

grant_user() публичный статический Метод

Grant a permission to a user
public static grant_user ( integer $user_id, integer $token_id, string $access = 'full' ) : Result
$user_id integer The user ID
$token_id integer The name or ID of the permission token to grant
$access string The kind of access to assign the group
Результат Result of the DB query

group_can() публичный статический Метод

Determine whether a group can perform a specific action
public static group_can ( mixed $group, mixed $token_id, string $access = 'full' ) : boolean
$group mixed A group ID or name
$token_id mixed A permission token ID or name
$access string Check for 'create', 'read', 'update', 'delete', or 'full' access
Результат boolean Whether the group can perform the action

group_cannot() публичный статический Метод

Determine whether a group is explicitly denied permission to perform a specific action This function does not return true if the group is merely not granted a permission
public static group_cannot ( $group, mixed $token_id ) : boolean
$token_id mixed A permission ID or name
Результат boolean True if access to the token is denied to the group

normalize_token() публичный статический Метод

Convert a token name into a valid format
public static normalize_token ( string $name ) : string
$name string The name of a permission
Результат string The permission with spaces converted to underscores and all lowercase

rebuild_permissions() публичный статический Метод

Reset premissions to their default state
public static rebuild_permissions ( $user = null )

revoke_group_token() публичный статический Метод

Remove a permission token from the group permissions table
public static revoke_group_token ( integer $group_id, mixed $token_id ) : the
$group_id integer The group ID
$token_id mixed The name or ID of the permission token
Результат the result of the DB query

revoke_user_token() публичный статический Метод

Remove a permission token from the user permissions table
public static revoke_user_token ( integer $user_id, mixed $token_id ) : the
$user_id integer The user ID
$token_id mixed The name or ID of the permission token
Результат the result of the DB query

token_description() публичный статический Метод

Fetch a permission token's description from the DB
public static token_description ( mixed $permission ) : string
$permission mixed a permission name or ID
Результат string the description of the permission

token_exists() публичный статический Метод

Determine whether a permission token exists
public static token_exists ( mixed $permission ) : boolean
$permission mixed a permission name or ID
Результат boolean whether the permission exists or not

token_id() публичный статический Метод

Get a permission token's ID by its name
public static token_id ( string $name ) : integer
$name string the name of the permission
Результат integer the permission's ID

token_name() публичный статический Метод

Get a permission token's name by its ID
public static token_name ( integer $id ) : string
$id integer a token ID
Результат string the name of the permission, or boolean false

user_can() публичный статический Метод

Determine whether a user can perform a specific action
public static user_can ( mixed $user, mixed $token_id, string $access = 'full' ) : boolean
$user mixed A user object, user ID or a username
$token_id mixed A permission ID or name
$access string Check for 'create', 'read', 'update', 'delete', or 'full' access
Результат boolean Whether the user can perform the action

user_cannot() публичный статический Метод

Determine whether a user is explicitly denied permission to perform a specific action This function does not return true if the user is merely not granted a permission
public static user_cannot ( mixed $user, mixed $token_id ) : boolean
$user mixed A User object, user ID or a username
$token_id mixed A permission ID or name
Результат boolean True if access to the token is denied to the user

user_tokens() публичный статический Метод

Get all the tokens for a given user with a particular kind of access
public static user_tokens ( mixed $user, string $access = 'full', $posts_only = false ) : array
$user mixed A user object, user ID or a username
$access string Check for 'create' or 'read', 'update', or 'delete' access
Результат array of token IDs