lithium\action\Controller::__invoke PHP Method

__invoke() public method

Called by the Dispatcher class to invoke an action.
public __invoke ( object $request, array $dispatchParams, array $options = [] ) : object
$request object The request object with URL and HTTP info for dispatching this action.
$dispatchParams array The array of parameters that will be passed to the action.
$options array The dispatch options for this action.
return object Returns the response object associated with this controller.
    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;
        });
    }