flight\Engine::before PHP Method

before() public method

Adds a pre-filter to a method.
public before ( string $name, callback $callback )
$name string Method name
$callback callback Callback function
    public function before($name, $callback)
    {
        $this->dispatcher->hook($name, 'before', $callback);
    }

Usage Example

Example #1
0
 function testFilterChaining()
 {
     $this->app->map('bye', function ($name) {
         return "Bye, {$name}!";
     });
     $this->app->before('bye', function (&$params, &$output) {
         $params[0] = 'Bob';
     });
     $this->app->before('bye', function (&$params, &$output) {
         $params[0] = 'Fred';
         return false;
     });
     $this->app->before('bye', function (&$params, &$output) {
         $params[0] = 'Ted';
     });
     $result = $this->app->bye('Joe');
     $this->assertEquals('Bye, Fred!', $result);
 }