예제 #1
0
 /**
  * Handle thrown exceptions
  *
  * @param \Exception $exception The Exception object
  * @return void
  */
 public static function handleException(\Exception $exception)
 {
     $request = new Request();
     try {
         $theme = new Theme(self::getKernel()->getConfig('theme'), $request->getBaseUrl());
         $view = new View($theme);
         $view->setParams(self::getKernel()->getConfig());
         if ($exception instanceof \Greengrape\Exception\NotFoundException) {
             $httpHeader = 'HTTP/1.1 404 Not Found';
             $templateFile = '404.html';
         } else {
             $httpHeader = 'HTTP/1.1 500 Internal Server Error';
             $templateFile = 'error.html';
         }
         if (!headers_sent()) {
             header($httpHeader);
         }
         $content = new Content('', $view);
         $content->setTemplateFile($templateFile);
         $content->setContent($exception->getMessage() . '<pre>' . $exception->getTraceAsString() . '</pre>');
         $vars = array('trace' => self::displayException($exception));
         echo $view->render($content, $vars);
     } catch (\Exception $newException) {
         $errorTitle = 'Exception found while handling exception:';
         $message = htmlentities($newException->getMessage());
         printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message);
         print self::displayException($newException);
         if ($newException->getMessage() != $exception->getMessage()) {
             $errorTitle = 'This was the original exception:';
             $message = htmlentities($exception->getMessage());
             printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message);
         }
     }
 }