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.
Ejemplo n.º 1
0
 /**
  * The default `'quit'` filter.
  */
 protected function _quit()
 {
     return Filter::on($this, 'quit', [$this->suite()->passed()], function ($chain, $success) {
     });
 }
Ejemplo n.º 2
0
     Stub::on($subclass)->method('::filterable', function () {
         return Filter::on(get_called_class(), 'filterable', func_get_args(), function ($chain, $message) {
             return "Hello {$message}";
         });
     });
     Filter::apply($class, 'filterable', 'spec.be_prefix');
     Filter::apply($subclass, 'filterable', 'spec.my_prefix');
     expect($subclass::filterable('World!'))->toBe('Hello Be My World!');
     expect($subclass::filterable('World!'))->toBe('Hello Be My World!');
 });
 it("invalidates parent cached filters", function () {
     $class = $this->class;
     $subclass = Stub::classname(['extends' => $class]);
     Stub::on($subclass)->method('::filterable', function () {
         return Filter::on(get_called_class(), 'filterable', func_get_args(), function ($chain, $message) {
             return "Hello {$message}";
         });
     });
     Filter::apply($class, 'filterable', 'spec.be_prefix');
     Filter::apply($subclass, 'filterable', 'spec.my_prefix');
     expect($subclass::filterable('World!'))->toBe('Hello Be My World!');
     Filter::apply($subclass, 'filterable', 'spec.no_chain');
     expect($subclass::filterable('World!'))->toBe("No Man's My World!");
 });
 it("throws an Exception when trying to apply a filter using an unexisting closure", function () {
     $class = $this->class;
     $closure = function () use($class) {
         Filter::apply($class, 'filterable', 'spec.unexisting_closure');
     };
     expect($closure)->toThrow(new Exception('Undefined filter `spec.unexisting_closure`.'));
 });