function testBeforeAndAfter() { $this->dispatcher->set('hello', function ($name) { return "Hello, {$name}!"; }); $this->dispatcher->hook('hello', 'before', function (&$params, &$output) { // Manipulate the parameter $params[0] = 'Fred'; }); $this->dispatcher->hook('hello', 'after', function (&$params, &$output) { // Manipulate the output $output .= " Have a nice day!"; }); $result = $this->dispatcher->run('hello', array('Bob')); $this->assertEquals('Hello, Fred! Have a nice day!', $result); }
/** * Handles calls to static methods. * * @param string $name Method name * @param array $params Method parameters * @return mixed Callback results */ public static function __callStatic($name, $params) { static $initialized = false; if (!$initialized) { require_once __DIR__ . '/autoload.php'; self::$engine = new \flight\Engine(); $initialized = true; } return \flight\core\Dispatcher::invokeMethod(array(self::$engine, $name), $params); }
/** * Handles calls to static methods. * * @param string $name Method name * @param array $params Method parameters * @return mixed Callback results * @throws \Exception */ public static function __callStatic($name, $params) { $app = Flight::app(); return \flight\core\Dispatcher::invokeMethod(array($app, $name), $params); }
function testInvalidCallback() { $this->setExpectedException('Exception', 'Invalid callback specified.'); $this->dispatcher->execute(array('NonExistentClass', 'nonExistentMethod')); }