Ejemplo n.º 1
0
 public function dispatch(BxZender_Controller_Request_AbstractRequest $request = null, Zend_Controller_Response_Abstract $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
         // Register with stack index of 100
         require_once 'BxZender/Controller/Plugin/ErrorHandler.php';
         $this->_plugins->registerPlugin(new BxZender_Controller_Plugin_ErrorHandler(), 100);
     }
     //if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
     //require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
     //Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new Zend_Controller_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())) {
         require_once 'BxZender/Controller/Request/Http.php';
         $request = new BxZender_Controller_Request_Http();
         $this->setRequest($request);
     }
     /**
      * Set base URL of request object, if available
      */
     //var_dump("BASE URL: " . $this->_baseUrl);
     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())) {
         require_once 'Zend/Controller/Response/Http.php';
         $response = new Zend_Controller_Response_Http();
         $this->setResponse($response);
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * 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;
                 //                    }
                 var_dump($e);
                 $this->_response->setException($e);
             }
         } while (!$this->_request->isDispatched());
     } catch (Exception $e) {
         //            if ($this->throwExceptions()) {
         //                throw $e;
         //            }
         $this->_response->setException($e);
     }
 }