lithium\aop\Filters::run()

public static method

Runs the chain and returns its result value. This method is used to make a method filterable.

All filters in the run will have access to given parameters. The implementation will be placed as the last item in the chain, so that effectively filters for the implementation wrap arround its implementation.

Creates Chain objects lazily, caches and reuses them with differing parameters for best of both worlds: lazy object construction to save upfront memory as well as quick re-execution. This method may be called quite often when filtered methods are executed inside a loop. Thus it tries to reduce overhead as much as possible. Optimized for the common case that no filters for a filtered method are present.

An example implementation function:

function($params) {
    $params['foo'] = 'bar';
    return $params['foo'];
}

Two examples to make a method filterable.

// Inside a static method.
Filters::run(get_called_class(), __FUNCTION__, $params, function($params) {
    return 'implementation';
});

// Inside an instance method.
Filters::run($this, __FUNCTION__, $params, function($params) {
    return 'implementation';
});

Parameters

  • string|object $class

    The fully namespaced name of a static class or an instance of a concrete class. Do not pass a class name for concrete classes. For instances will use a set of merged filters. First class filter, then instance filters.

  • string $method

    The method name i.e. 'bar'.

  • array $params
  • callable $implementation

Returns

mixed

The result of running the chain.

Source

	public static function run($class, $method, array $params, $implementation) {
		if (!static::hasApplied($class, $method)) {
			return $implementation($params);
		}
		return static::_chain($class, $method)->run($params, $implementation);
	}