lithium\aop\Filters::apply()
Lazily applies a filter to a method.
Classes aliased via class_alias()
are treated as entirely separate from
their original class.
When calling apply after previous runs (rarely happens), this method will invalidate the chain cache.
Multiple applications of a filter will add the filter multiple times to the chain. It is up to the user to keep the list of filters unique.
This method intentionally does not establish class context for closures by binding them to the instance or statically to the class. Closures can originate from static and instance methods and PHP does not allow to rebind a closure from a static method to an instance.
Parameters
-
string|object
$class
The fully namespaced name of a static class or an instance of a concrete class to which the filter will be applied. Passing a class name for a concrete class will apply the filter to all instances of that class.
-
string
$method
The method name to which the filter will be applied i.e.
'bar'
. -
callable
$filter
The filter to apply to the class method. Can be anykind of a callable, most often this is a closure.
Returns
voidSource
public static function apply($class, $method, $filter) {
list($id,) = static::_ids($class, $method);
if (!isset(static::$_filters[$id])) {
static::$_filters[$id] = [];
}
static::$_filters[$id][] = $filter;
if (isset(static::$_chains[$id])) {
unset(static::$_chains[$id]);
}
}