public static function run($request, array $options = array())
{
$router = static::$_classes['router'];
$params = compact('request', 'options');
return static::_filter(__FUNCTION__, $params, function ($self, $params) use($router) {
$request = $params['request'];
$options = $params['options'];
if (($result = $router::process($request)) instanceof Response) {
return $result;
}
$params = $self::applyRules($result->params);
if (!$params) {
throw new DispatchException('Could not route request.');
}
$callable = $self::invokeMethod('_callable', array($result, $params, $options));
return $self::invokeMethod('_call', array($callable, $result, $params));
});
}