PHP Class li3_access\extensions\adapter\security\access\Rules

Inheritance: extends lithium\core\Object
Show file Open project: tmaiaroto/li3_access Class Usage Examples

Protected Properties

Property Type Description
$_autoConfig array Configuration that will be automatically assigned to class properties.
$_default array Lists a subset of rules defined in $_rules which should be checked by default on every call to check() (unless overridden by passed options).
$_rules array Rules are named closures that must either return true or false.

Public Methods

Method Description
__construct ( array $config = [] ) Sets default adapter configuration.
add ( string $name, function $rule = null ) Adds an Access rule. This works much like the Validator class.
check ( mixed $user, mixed $params, array $options = [] ) : array The Rules adapter will use check to test the provided data against a number of given rules. Extra data that may be required to make an informed decision about access can be passed in the $options array. This extra data will vary from app to app and rules will need to be added to handle it. The default rules assume some general cases and more can be added or passed directly to this method.
get ( string $name = null ) : mixed Simply returns the rules that are currently available. Optionally, passing a name will return just that rule or false if it doesn't exist.
getRules ( string $name = null )

Protected Methods

Method Description
_call ( array $rule, mixed $user, mixed $request, array $options ) : boolean Extracts a callable rule either from a rule definition assigned as a closure, or a string reference to a rule defined in a key in the $_rules array.
_init ( ) : void Initializes default rules to use.

Method Details

__construct() public method

Sets default adapter configuration.
public __construct ( array $config = [] )
$config array Adapter configuration, which includes the following default options: - `'rules'` _array_: An array of rules to be added to the default rules initialized by the adapter. See the `'rules'` option of the `check()` method for more information on the acceptable format of these values. - `'default'` _array_: The default list of rules to use when performing access checks. - `'allowAny'` _boolean_: If set to `true`, access checks will return successful if _any_ access rule passes. Otherwise, all are required to pass in order for the check to succeed. Defaults to `false`.

_call() protected method

Extracts a callable rule either from a rule definition assigned as a closure, or a string reference to a rule defined in a key in the $_rules array.
protected _call ( array $rule, mixed $user, mixed $request, array $options ) : boolean
$rule array The rule definition array.
$user mixed The value representing the user making the request. Usually an array.
$request mixed The value representing request data or the object being access.
$options array Any options passed to `check()`.
return boolean Returns `true` if the call to the rule was successful, otherwise `false` if the call failed, or if a callable rule was not found.

_init() protected method

Initializes default rules to use.
protected _init ( ) : void
return void

add() public method

All rules should be anonymous functions and will be passed $user, $request, and $options which will contain the entire rule array which contains its own name plus other data that could be used to determine access.
public add ( string $name, function $rule = null )
$name string The rule name.
$rule function The closure for the rule, which has to return true or false.

check() public method

The Rules adapter will use check to test the provided data against a number of given rules. Extra data that may be required to make an informed decision about access can be passed in the $options array. This extra data will vary from app to app and rules will need to be added to handle it. The default rules assume some general cases and more can be added or passed directly to this method.
public check ( mixed $user, mixed $params, array $options = [] ) : array
$user mixed The user data array that holds all necessary information about the user requesting access. Or false (because `Auth::check()` can return `false`).
$params mixed The Lithium `Request` object, or an array with at least 'request', and 'params'
$options array An array of additional options.
return array An empty array if access is allowed and an array with reasons for denial if denied.

get() public method

Simply returns the rules that are currently available. Optionally, passing a name will return just that rule or false if it doesn't exist.
public get ( string $name = null ) : mixed
$name string The rule name (optional).
return mixed Either an array of rule closures, a single rule closure, or `false`.

getRules() public method

Deprecation:
public getRules ( string $name = null )
$name string The rule name (optional).

Property Details

$_autoConfig protected property

Configuration that will be automatically assigned to class properties.
protected array $_autoConfig
return array

$_default protected property

Lists a subset of rules defined in $_rules which should be checked by default on every call to check() (unless overridden by passed options).
protected array $_default
return array

$_rules protected property

Rules are named closures that must either return true or false.
protected array $_rules
return array