Пример #1
0
 public function testMissingViewScriptDoesDoubleRender()
 {
     \Zend\Controller\Action\HelperBroker\HelperBroker::getStack()->offsetSet(-91, new \Zend\Controller\Action\Helper\ViewRenderer());
     // go to the test controller for this funcitonal test
     $this->dispatch('/zend-layout-functional-test-test/missing-view-script');
     $this->assertEquals(trim($this->response->getBody()), "[DEFAULT_LAYOUT_START]\n[DEFAULT_LAYOUT_START]\n[DEFAULT_LAYOUT_END]\n(ErrorController::errorAction output)[DEFAULT_LAYOUT_END]");
 }
Пример #2
0
 /**
  * Initialize action helper
  *
  * @return void
  */
 protected function _initHelper()
 {
     $helperClass = $this->getHelperClass();
     if (!HelperBroker\HelperBroker::hasHelper('layout')) {
         if (!class_exists($helperClass)) {
             \Zend\Loader::loadClass($helperClass);
         }
         HelperBroker\HelperBroker::getStack()->offsetSet(-90, new $helperClass($this));
     }
 }
Пример #3
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param \Zend\Controller\Request\AbstractRequest|null $request
  * @param \Zend\Controller\Response\AbstractResponse|null $response
  * @return void|\Zend\Controller\Response\AbstractResponse Returns response object if returnResponse() is true
  */
 public function dispatch(Request\AbstractRequest $request = null, Response\AbstractResponse $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('\\Zend\\Controller\\Plugin\\ErrorHandler')) {
         // Register with stack index of 100
         $this->_plugins->registerPlugin(new Plugin\ErrorHandler(), 100);
     }
     if (!$this->getParam('noViewRenderer') && !Action\HelperBroker\HelperBroker::hasHelper('viewRenderer')) {
         Action\HelperBroker\HelperBroker::getStack()->offsetSet(-80, new Action\Helper\ViewRenderer());
     }
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null !== $request) {
         $this->setRequest($request);
     } elseif (null === $request && null === ($request = $this->getRequest())) {
         $request = new Request\HTTP();
         $this->setRequest($request);
     }
     /**
      * Set base URL of request object, if available
      */
     if (is_callable(array($this->_request, 'setBaseUrl'))) {
         if (null !== $this->_baseUrl) {
             $this->_request->setBaseUrl($this->_baseUrl);
         }
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null !== $response) {
         $this->setResponse($response);
     } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) {
         $response = new Response\HTTP();
         $this->setResponse($response);
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     $router->setParams($this->getParams());
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         /**
          * Notify plugins of router startup
          */
         $this->_plugins->routeStartup($this->_request);
         try {
             $router->route($this->_request);
         } catch (\Exception $e) {
             if ($this->throwExceptions()) {
                 throw $e;
             }
             $this->_response->setException($e);
         }
         /**
          * Notify plugins of router completion
          */
         $this->_plugins->routeShutdown($this->_request);
         /**
          * Notify plugins of dispatch loop startup
          */
         $this->_plugins->dispatchLoopStartup($this->_request);
         /**
          *  Attempt to dispatch the controller/action. If the $this->_request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $this->_request->setDispatched(true);
             /**
              * Notify plugins of dispatch startup
              */
             $this->_plugins->preDispatch($this->_request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             if (!$this->_request->isDispatched()) {
                 continue;
             }
             /**
              * Dispatch request
              */
             try {
                 $dispatcher->dispatch($this->_request, $this->_response);
             } catch (\Exception $e) {
                 if ($this->throwExceptions()) {
                     throw $e;
                 }
                 $this->_response->setException($e);
             }
             /**
              * Notify plugins of dispatch completion
              */
             $this->_plugins->postDispatch($this->_request);
         } while (!$this->_request->isDispatched());
     } catch (\Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     /**
      * Notify plugins of dispatch loop completion
      */
     try {
         $this->_plugins->dispatchLoopShutdown();
     } catch (\Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     if ($this->returnResponse()) {
         return $this->_response;
     }
     $this->_response->sendResponse();
 }