PHP Class Authority\Rule

Authority is an authorization library for CodeIgniter 2+ and PHPActiveRecord This library is inspired by, and largely based off, Ryan Bates' CanCan gem for Ruby on Rails. It is not a 1:1 port, but the essentials are available. Please check out his work at http://github.com/ryanb/cancan/
Author: Matthew Machuga
Show file Open project: machuga/authority Class Usage Examples

Protected Properties

Property Type Description
$action Action the rule applies to
$behavior True defines a privilege, false defines a restriction
$conditions Array of conditions (closures) to check rule against

Public Methods

Method Description
__construct ( boolean $behavior, string $action, string | mixed $resource, Closure | null $condition = null ) Rule constructor
addCondition ( Closure $condition ) : void Add a condition for the rule to check against
getAction ( ) : string Returns action this rule represents
getBehavior ( ) : boolean Returns whether rule is a privilege or a restriction
getResource ( ) : mixed Returns resource this rule represents
isAllowed ( ) : boolean Determine if current rule allows access
isPrivilege ( ) : boolean Determine if rule is a privilege
isRelevant ( string $action, string | mixed $resource ) : boolean Determine if current rule is relevant based on an action and resource
isRestriction ( ) : boolean Determine if rule is a restriction
matchesAction ( string $action ) : boolean Determine if the instance's action matches the one passed in
matchesResource ( string | mixed $resource ) : boolean Determine if the instance's resource matches the one passed in
setAction ( string $action ) : void Set instance action
setBehavior ( boolean $behavior ) : void Set instance behavior
setResource ( string | mixed $resource ) : void Set instance resource
when ( $condition ) : void API friendly alias for addCondition

Method Details

__construct() public method

Rule constructor
public __construct ( boolean $behavior, string $action, string | mixed $resource, Closure | null $condition = null )
$behavior boolean Determines if privilege or restriction
$action string Action the rule applies to
$resource string | mixed Name of resource or instance of object
$condition Closure | null Optional closure to act as a condition

addCondition() public method

Add a condition for the rule to check against
public addCondition ( Closure $condition ) : void
$condition Closure Condition callback for rule to utilize
return void

getAction() public method

Returns action this rule represents
public getAction ( ) : string
return string

getBehavior() public method

Returns whether rule is a privilege or a restriction
public getBehavior ( ) : boolean
return boolean

getResource() public method

Returns resource this rule represents
public getResource ( ) : mixed
return mixed

isAllowed() public method

Determine if current rule allows access
public isAllowed ( ) : boolean
return boolean

isPrivilege() public method

Determine if rule is a privilege
public isPrivilege ( ) : boolean
return boolean

isRelevant() public method

Determine if current rule is relevant based on an action and resource
public isRelevant ( string $action, string | mixed $resource ) : boolean
$action string Action in question
$resource string | mixed Name of resource or instance of object
return boolean

isRestriction() public method

Determine if rule is a restriction
public isRestriction ( ) : boolean
return boolean

matchesAction() public method

Determine if the instance's action matches the one passed in
public matchesAction ( string $action ) : boolean
$action string Action in question
return boolean

matchesResource() public method

Determine if the instance's resource matches the one passed in
public matchesResource ( string | mixed $resource ) : boolean
$resource string | mixed Name of resource or instance of object
return boolean

setAction() public method

Set instance action
public setAction ( string $action ) : void
$action string Action for rule to use
return void

setBehavior() public method

Set instance behavior
public setBehavior ( boolean $behavior ) : void
$behavior boolean True for privilege, false for restriction
return void

setResource() public method

Set instance resource
public setResource ( string | mixed $resource ) : void
$resource string | mixed Set resource for rule to be checked against
return void

when() public method

API friendly alias for addCondition
public when ( $condition ) : void
return void

Property Details

$action protected property

Action the rule applies to
protected $action

$behavior protected property

True defines a privilege, false defines a restriction
protected $behavior

$conditions protected property

Array of conditions (closures) to check rule against
protected $conditions