PHP Class Kahlan\Filter\Filter

Show file Open project: crysalead/kahlan Class Usage Examples

Protected Properties

Property Type Description
$_aspects array An array of Closure indexed by a name identifier.
$_cachedFilters array A cached array of filters indexed by class name & method name.
$_enabled boolean Indicates if the filter system is enabled or not.
$_methodFilters array An array of MethodFilters indexed by class name.

Public Methods

Method Description
_classFilters ( mixed $context, string $method ) : array Gets the whole filters associated to a class/instance's method.
apply ( mixed $context, string | array $methods, string $name ) : string Applies a filter to a method.
detach ( mixed $context, string $method, $name = null ) Detaches a filter completely, by class/instance or on a method basis.
enable ( boolean $active = true ) Enables/disables the filter system.
filters ( mixed $context = null, string | null $method = null ) : array Gets the whole filters data or filters associated to a class/instance's method.
on ( mixed $context, string $method, array $params, Closure $callback, array $filters = [] ) : mixed Cuts the normal execution of a method to run all applied filter for the method.
register ( string | array | Closur\Closure $name, $aspect = null ) : string | null Registers an aspect in the system.
registered ( string | null $name = null ) : boolean Checks if as aspect exists or returns all registered aspects if $name is null.
reset ( ) Removes filters for all classes.
unregister ( string $name ) Unregisters an aspect in the system.

Protected Methods

Method Description
_methodFilters ( string | object $context ) : object Gets the MethodFilters instance of a context.

Method Details

_classFilters() public static method

Gets the whole filters associated to a class/instance's method.
public static _classFilters ( mixed $context, string $method ) : array
$context mixed The class/instance context.
$method string The name of the method to get the filters from.
return array The whole filters data or filters associated to a class/instance's method.

_methodFilters() protected static method

Gets the MethodFilters instance of a context.
protected static _methodFilters ( string | object $context ) : object
$context string | object The class/instance context.
return object

apply() public static method

Applies a filter to a method.
public static apply ( mixed $context, string | array $methods, string $name ) : string
$context mixed The instance or class name context to apply a new filter.
$methods string | array The name or array of method names to be filtered.
$name string The filter name to apply.
return string The name reference of the applied filter.

detach() public static method

Detaches a filter completely, by class/instance or on a method basis.
public static detach ( mixed $context, string $method, $name = null )
$context mixed The instance or class name context to apply a new filter.
$method string The name of the method to apply the filter.

enable() public static method

Enables/disables the filter system.
public static enable ( boolean $active = true )
$active boolean

filters() public static method

Or sets the whole filters data.
public static filters ( mixed $context = null, string | null $method = null ) : array
$context mixed If `null` returns the whole filters data. If `$context` is an array use `$context` as the whole filters data. Otherwise `$context` stands for the class/instance context.
$method string | null The name of the method to get the filters from or `null` to get all of them.
return array The whole filters data or filters associated to a class/instance's method.

on() public static method

Cuts the normal execution of a method to run all applied filter for the method.
public static on ( mixed $context, string $method, array $params, Closure $callback, array $filters = [] ) : mixed
$context mixed The instance or class name context to perform the filtering on.
$method string The name of the method which is going the be filtered.
$params array The parameters passed to the original method.
$callback Closure The original method logic closure.
$filters array Additional filters to apply to the method for this call only.
return mixed Returns The result of the chain.

register() public static method

Registers an aspect in the system.
public static register ( string | array | Closur\Closure $name, $aspect = null ) : string | null
$name string | array | Closur\Closure The aspect name identifier, the aspects array or the aspect closure.
return string | null The registered aspect name identifier or `null` for multiple registration.

registered() public static method

Checks if as aspect exists or returns all registered aspects if $name is null.
public static registered ( string | null $name = null ) : boolean
$name string | null The aspect name identifier or `null` to get all registered aspects.
return boolean

reset() public static method

Removes filters for all classes.
public static reset ( )

unregister() public static method

Unregisters an aspect in the system.
public static unregister ( string $name )
$name string The aspect name identifier to unregister.

Property Details

$_aspects protected static property

An array of Closure indexed by a name identifier.
protected static array $_aspects
return array

$_cachedFilters protected static property

A cached array of filters indexed by class name & method name.
protected static array $_cachedFilters
return array

$_enabled protected static property

Indicates if the filter system is enabled or not.
protected static bool $_enabled
return boolean

$_methodFilters protected static property

An array of MethodFilters indexed by class name.
protected static array $_methodFilters
return array