lithium\util\collection\Filters::run PHP Method

run() public static method

Collects a set of filters to iterate. Creates a filter chain for the given class/method, executes it, and returns the value.
public static run ( mixed $class, array $params, array $options = [] ) : Returns
$class mixed The class for which this filter chain is being created. If this is the result of a static method call, `$class` should be a string. Otherwise, it should be the instance of the object making the call.
$params array An associative array of the given method's parameters.
$options array The configuration options with which to create the filter chain. Mainly, these options allow the `Filters` object to be queried for details such as which class / method initiated it. Available keys: - `'class'`: The name of the class that initiated the filter chain. - `'method'`: The name of the method that initiated the filter chain. - `'data'` _array_: An array of callable objects (usually closures) to be iterated through. By default, execution will be nested such that the first item will be executed first, and will be the last to return.
return Returns the value returned by the first closure in `$options['data`]`.
    public static function run($class, $params, array $options = array())
    {
        $defaults = array('class' => null, 'method' => null, 'data' => array());
        $options += $defaults;
        $lazyFilterCheck = is_string($class) && $options['method'];
        if ($lazyFilterCheck && isset(static::$_lazyFilters[$class][$options['method']])) {
            $filters = static::$_lazyFilters[$class][$options['method']];
            unset(static::$_lazyFilters[$class][$options['method']]);
            $options['data'] = array_merge($filters, $options['data']);
            foreach ($filters as $filter) {
                $class::applyFilter($options['method'], $filter);
            }
        }
        $chain = new Filters($options);
        $next = $chain->rewind();
        return $next($class, $params, $chain);
    }

Usage Example

 public function testRunWithoutChain()
 {
     $options = array('method' => __FUNCTION__, 'class' => __CLASS__, 'items' => array(function ($self, $params, $chain) {
         return $chain->next($self, $params, null);
     }, 'This is a filter chain that calls $chain->next() without the $chain argument.'));
     $result = Filters::run(__CLASS__, array(), $options);
     $expected = 'This is a filter chain that calls $chain->next() without the $chain argument.';
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\util\collection\Filters::run