Kahlan\Filter\Filter::on PHP 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.
    public static function on($context, $method, $params, $callback, $filters = [])
    {
        if (!static::$_enabled) {
            array_unshift($params, null);
            return call_user_func_array($callback, $params);
        }
        $filters = array_merge(static::filters($context, $method), $filters, [$callback]);
        $chain = new Chain(compact('filters', 'method', 'params'));
        $closure = $chain->rewind();
        array_unshift($params, $chain);
        return call_user_func_array($closure, $params);
    }

Usage Example

示例#1
0
 /**
  * The default `'quit'` filter.
  */
 protected function _quit()
 {
     return Filter::on($this, 'quit', [$this->suite()->passed()], function ($chain, $success) {
     });
 }
All Usage Examples Of Kahlan\Filter\Filter::on