public function __invoke($request, $dispatchParams, array $options = array())
{
$render =& $this->_render;
$params = compact('request', 'dispatchParams', 'options');
return $this->_filter(__METHOD__, $params, function ($self, $params) use(&$render) {
$dispatchParams = $params['dispatchParams'];
$action = isset($dispatchParams['action']) ? $dispatchParams['action'] : 'index';
$args = isset($dispatchParams['args']) ? $dispatchParams['args'] : array();
if (substr($action, 0, 1) === '_' || method_exists(__CLASS__, $action)) {
throw new DispatchException('Attempted to invoke a private method.');
}
if (!method_exists($self, $action)) {
throw new DispatchException("Action `{$action}` not found.");
}
$render['template'] = $render['template'] ?: $action;
if ($result = $self->invokeMethod($action, $args)) {
if (is_string($result)) {
$self->render(array('text' => $result));
return $self->response;
}
if (is_array($result)) {
$self->set($result);
}
}
if (!$render['hasRendered'] && $render['auto']) {
$self->render();
}
return $self->response;
});
}