Ejemplo n.º 1
0
 /**
  * Handle errors and exceptions
  *
  * If the 'noErrorHandler' front Controller flag has been set,
  * returns early.
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 protected function _handleError(RThink_Controller_Request $request, RThink_Controller_Response $response)
 {
     $frontController = RThink_Controller_Front::getInstance();
     if ($frontController->getParam('noErrorHandler')) {
         return;
     }
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front Controller to throw it
             $frontController->throwExceptions(true);
             throw array_pop($exceptions);
         }
     }
     // check for an exception AND allow the error handler Controller the option to forward
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         $this->_isInsideErrorHandlerLoop = true;
         // Get exception information
         $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
         $exceptions = $response->getException();
         $exception = $exceptions[0];
         $error->exception = $exception;
         $exceptionType = get_class($exception);
         $error->exception = $exception;
         switch ($exceptionType) {
             case 'RThink_Controller_Router_Exception':
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ROUTE;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             case 'RThink_Controller_Dispatcher_Exception':
                 $error->type = self::EXCEPTION_NO_CONTROLLER;
                 break;
             case 'RThink_Controller_Action_Exception':
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ACTION;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             default:
                 $error->type = self::EXCEPTION_OTHER;
                 break;
         }
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Keep a copy of the original Request
         $error->request = clone $request;
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction())->setDispatched(false);
     }
 }