PHP Класс Authority\Authority

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$aliases List of aliases for groups of actions
$currentUser Current user in the application for rules to apply to
$dispatcher Dispatcher for events
$rules Collection of rules

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

Метод Описание
__construct ( mixed $currentUser, mixed $dispatcher = null ) Authority constructor
addAlias ( string $name, array $actions ) : authority\RuleAlias Define new alias for an action
addRule ( boolean $allow, array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule Define rule for a given action and resource
allow ( array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule Define privilege for a given action and resource
can ( $action, $resource, $resourceValue = null ) : boolean Determine if current user can access the given action and resource
cannot ( $action, $resource, $resourceValue = null ) : boolean Determine if current user cannot access the given action and resource Returns negation of can()
deny ( array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule Define restriction for a given action and resource
dispatch ( string $eventName, mixed $payload = [] ) : mixed | null Fires event from current dispatcher
getAlias ( $name ) : authority\RuleAlias | null Returns a RuleAlias for a given action name
getAliases ( ) : array Returns all aliases
getAliasesForAction ( $action ) : array Returns all actions a given action applies to
getCurrentUser ( ) : mixed Returns current user
getRules ( ) : RuleRepository Returns the current rule set
getRulesFor ( $action, $resource ) : RuleRepository Returns all rules relevant to the given action and resource
setCurrentUser ( mixed $currentUser ) : void Set current user
setDispatcher ( mixed $dispatcher ) : void Set dispatcher
user ( ) : mixed Returns current user - alias of getCurrentUser()

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

__construct() публичный Метод

Authority constructor
public __construct ( mixed $currentUser, mixed $dispatcher = null )
$currentUser mixed Current user in the application
$dispatcher mixed Dispatcher used for firing events

addAlias() публичный Метод

Define new alias for an action
public addAlias ( string $name, array $actions ) : authority\RuleAlias
$name string Name of action
$actions array Actions that $name aliases
Результат authority\RuleAlias

addRule() публичный Метод

Define rule for a given action and resource
public addRule ( boolean $allow, array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule
$allow boolean True if privilege, false if restriction
$actions array | string Action for the rule
$resource mixed Resource for the rule
$condition Closure | null Optional condition for the rule
Результат array | Rule

allow() публичный Метод

Define privilege for a given action and resource
public allow ( array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule
$actions array | string Action for the rule
$resource mixed Resource for the rule
$condition Closure | null Optional condition for the rule
Результат array | Rule

can() публичный Метод

Determine if current user can access the given action and resource
public can ( $action, $resource, $resourceValue = null ) : boolean
Результат boolean

cannot() публичный Метод

Determine if current user cannot access the given action and resource Returns negation of can()
public cannot ( $action, $resource, $resourceValue = null ) : boolean
Результат boolean

deny() публичный Метод

Define restriction for a given action and resource
public deny ( array | string $actions, mixed $resource, Closure | null $condition = null ) : array | Rule
$actions array | string Action for the rule
$resource mixed Resource for the rule
$condition Closure | null Optional condition for the rule
Результат array | Rule

dispatch() публичный Метод

Fires event from current dispatcher
public dispatch ( string $eventName, mixed $payload = [] ) : mixed | null
$eventName string
$payload mixed
Результат mixed | null

getAlias() публичный Метод

Returns a RuleAlias for a given action name
public getAlias ( $name ) : authority\RuleAlias | null
Результат authority\RuleAlias | null

getAliases() публичный Метод

Returns all aliases
public getAliases ( ) : array
Результат array

getAliasesForAction() публичный Метод

Returns all actions a given action applies to
public getAliasesForAction ( $action ) : array
Результат array

getCurrentUser() публичный Метод

Returns current user
public getCurrentUser ( ) : mixed
Результат mixed

getRules() публичный Метод

Returns the current rule set
public getRules ( ) : RuleRepository
Результат RuleRepository

getRulesFor() публичный Метод

Returns all rules relevant to the given action and resource
public getRulesFor ( $action, $resource ) : RuleRepository
Результат RuleRepository

setCurrentUser() публичный Метод

Set current user
public setCurrentUser ( mixed $currentUser ) : void
$currentUser mixed Current user in the application
Результат void

setDispatcher() публичный Метод

Set dispatcher
public setDispatcher ( mixed $dispatcher ) : void
$dispatcher mixed Dispatcher to fire events
Результат void

user() публичный Метод

Returns current user - alias of getCurrentUser()
public user ( ) : mixed
Результат mixed

Описание свойств

$aliases защищенное свойство

List of aliases for groups of actions
protected $aliases

$currentUser защищенное свойство

Current user in the application for rules to apply to
protected $currentUser

$dispatcher защищенное свойство

Dispatcher for events
protected $dispatcher

$rules защищенное свойство

Collection of rules
protected $rules