Beispiel #1
0
    /**
     * Retrieve rendered contents of a controller action
     *
     * If the action results in a forward or redirect, returns empty string.
     *
     * @param  string $action
     * @param  string $controller
     * @param  string $module Defaults to default module
     * @param  array $params
     * @return string
     */
    public function __invoke($action, $controller, $module = null, array $params = array())
    {
        $this->resetObjects();
        if (null === $module) {
            $module = $this->defaultModule;
        }

        // clone the view object to prevent over-writing of view variables
        $broker = $this->front->getHelperBroker();
        $viewRenderer = $broker->load('viewRenderer');
        $viewRendererClone = clone $viewRenderer;
        $broker->register('viewRenderer', $viewRendererClone);

        $this->request->setParams($params)
                      ->setModuleName($module)
                      ->setControllerName($controller)
                      ->setActionName($action)
                      ->setDispatched(true);

        $this->dispatcher->dispatch($this->request, $this->response);

        // reset the viewRenderer object to it's original state
        $broker->register('viewRenderer', $viewRenderer);

        if (!$this->request->isDispatched()
            || $this->response->isRedirect())
        {
            // forwards and redirects render nothing
            return '';
        }

        $return = $this->response->getBody();
        $this->resetObjects();
        return $return;
    }
Beispiel #2
0
 public function testViewRendererHelperNotRegisteredIfNoViewRendererSet()
 {
     $broker = $this->_controller->getHelperBroker();
     $this->assertFalse($broker->hasPlugin('viewRenderer'));
     $this->_controller->setParam('noViewRenderer', true);
     $request = new Request\Http('http://example.com/index/index');
     $this->_controller->setResponse(new Response\Cli());
     $response = $this->_controller->dispatch($request);
     $this->assertFalse($broker->hasPlugin('viewRenderer'));
 }