PHP Class Efficiently\AuthorityController\Authority

Inheritance: extends Authority\Authority
Show file Open project: efficiently/authority-controller

Protected Properties

Property Type Description
$aliasedActions

Public Methods

Method Description
__construct ( mixed $currentUser, mixed $dispatcher = null ) Authority constructor
addAlias ( string $name, string | array $actions ) : RuleAlias Define new alias for an action
addRule ( boolean $allow, string | array $actions, mixed $resources, Closure | null $condition = null ) : array Define rule(s) for a given action(s) and resource(s)
addRules ( $allow, $actions, $resources, $condition = null ) alias of addRule()
authorize ( $action, $resource, $args = null )
can ( $action, $resource, $resourceValue = null ) : boolean Determine if current user can access the given action and resource
clearAliasedActions ( ) Removes previously aliased actions including the defaults.
getAliases ( ) : array Returns an associative array of aliases.
getAliasesForAction ( $action ) This does the opposite kind of lookup as 'getExpandActions()'.
getExpandActions ( $actions ) rely on the actions to be expanded.
getRelevantConditions ( string | array $action, string | object $resource ) : array
getRulesFor ( $action, $resource ) : RuleRepository Returns all rules relevant to the given action and resource
getUnauthorizedMessage ( $action, $subject )
hasCondition ( string | array $action, string | object $resource ) : boolean

Protected Methods

Method Description
addAliasAction ( $target, $actions )
getAliasedActions ( ) The key is the target and the value is an array of actions aliasing the key.
getDefaultAliasActions ( )
getUnauthorizedMessageKeys ( $action, $subject )
initDefaultAliases ( )
validateTarget ( $target ) User shouldn't specify targets with names of real actions or it will cause Seg fault

Method Details

__construct() public method

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

addAlias() public method

$this->$authority->addAlias('read', ['index', 'show']); $this->$authority->addAlias('create', 'new'); $this->$authority->addAlias('update', 'edit'); This way one can use $params['action'] in the controller to determine the permission.
public addAlias ( string $name, string | array $actions ) : RuleAlias
$name string Name of action
$actions string | array Action(s) that $name aliases
return RuleAlias

addAliasAction() protected method

protected addAliasAction ( $target, $actions )

addRule() public method

Define rule(s) for a given action(s) and resource(s)
public addRule ( boolean $allow, string | array $actions, mixed $resources, Closure | null $condition = null ) : array
$allow boolean True if privilege, false if restriction
$actions string | array Action(s) for the rule(s)
$resources mixed Resource(s) for the rule(s)
$condition Closure | null Optional condition for the rule
return array

addRules() public method

alias of addRule()
public addRules ( $allow, $actions, $resources, $condition = null )

authorize() public method

public authorize ( $action, $resource, $args = null )

can() public method

Determine if current user can access the given action and resource
public can ( $action, $resource, $resourceValue = null ) : boolean
return boolean

clearAliasedActions() public method

Removes previously aliased actions including the defaults.
public clearAliasedActions ( )

getAliasedActions() protected method

The key is the target and the value is an array of actions aliasing the key.
protected getAliasedActions ( )

getAliases() public method

The key is the target and the value is an array of actions aliasing the key.
public getAliases ( ) : array
return array

getAliasesForAction() public method

This does the opposite kind of lookup as 'getExpandActions()'.
public getAliasesForAction ( $action )

getDefaultAliasActions() protected method

protected getDefaultAliasActions ( )

getExpandActions() public method

rely on the actions to be expanded.
public getExpandActions ( $actions )

getRelevantConditions() public method

public getRelevantConditions ( string | array $action, string | object $resource ) : array
$action string | array Name of action(s)
$resource string | object Resource for the rule
return array

getRulesFor() public method

Returns all rules relevant to the given action and resource
public getRulesFor ( $action, $resource ) : RuleRepository
return RuleRepository

getUnauthorizedMessage() public method

public getUnauthorizedMessage ( $action, $subject )

getUnauthorizedMessageKeys() protected method

protected getUnauthorizedMessageKeys ( $action, $subject )

hasCondition() public method

public hasCondition ( string | array $action, string | object $resource ) : boolean
$action string | array Name of action(s)
$resource string | object Resource for the rule
return boolean

initDefaultAliases() protected method

protected initDefaultAliases ( )

validateTarget() protected method

User shouldn't specify targets with names of real actions or it will cause Seg fault
protected validateTarget ( $target )

Property Details

$aliasedActions protected property

protected $aliasedActions