Пример #1
0
 /**
  * The handle error function checks for an exception and
  * allows the error handler controller the option to forward
  *
  * @param Enlight_Controller_Front $front
  * @param Enlight_Controller_Request_Request $request
  * @return mixed
  * @throws mixed
  */
 protected function handleError($front, Enlight_Controller_Request_Request $request)
 {
     if ($front->getParam('noErrorHandler')) {
         return;
     }
     $response = $front->Response();
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front controller to throw it
             $front->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;
         switch (true) {
             case $exception instanceof Zend_Controller_Router_Exception:
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ROUTE;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             case $exception instanceof Zend_Controller_Dispatcher_Exception:
                 $error->type = self::EXCEPTION_NO_CONTROLLER;
                 break;
             case $exception instanceof Zend_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;
         }
         // Keep a copy of the original request
         $error->request = clone $request;
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setControllerName('error')->setActionName('error')->setDispatched(false);
         //->setModuleName($this->getErrorHandlerModule())
         //->setControllerName($this->getErrorHandlerController())
         //->setActionName($this->getErrorHandlerAction())
     }
 }
Пример #2
0
 /**
  * The handle error function checks for an exception and
  * allows the error handler controller the option to forward
  *
  * @param Enlight_Controller_Front $front
  * @param Enlight_Controller_Request_Request $request
  * @return mixed
  * @throws mixed
  */
 protected function handleError($front, Enlight_Controller_Request_Request $request)
 {
     if ($front->getParam('noErrorHandler')) {
         return;
     }
     $response = $front->Response();
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front controller to throw it
             $front->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;
         // Keep a copy of the original request
         $error->request = clone $request;
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setControllerName('error')->setActionName('error')->setDispatched(false);
     }
 }