Пример #1
0
 /**
  * exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Eight::lang()
  * @uses    Eight_Exception::text()
  * @param   object   exception object
  * @return  void
  */
 public static function handle(Exception $e)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         // Create a text version of the exception
         $error = Eight_Exception::text($e);
         // Add this exception to the log
         Eight::log('error', $error);
         // Manually save logs after exceptions
         Eight::log_save();
         if (Eight::config('core.display_errors') === FALSE && Eight::$force_show_errors !== YES) {
             // Do not show the details
             $file = $line = NULL;
             $trace = array();
             $template = '_disabled';
         } else {
             $file = $e->getFile();
             $line = $e->getLine();
             $trace = $e->getTrace();
             $template = Eight::$server_api == 'cli' ? '_cli' : '';
         }
         if (Eight::$server_api != 'cli') {
             header("Content-Type: text/html;charset=utf-8");
         }
         if ($e instanceof Eight_Exception) {
             $template = $e->getTemplate() . $template;
             if (!headers_sent()) {
                 $e->sendHeaders();
             }
             // Use the human-readable error name
             $code = Eight::lang('4' . $code);
         } else {
             $template = Eight_Exception::$template . $template;
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             if ($e instanceof ErrorException) {
                 // Use the human-readable error name
                 $code = Eight::lang('4' . $e->getSeverity());
                 if (version_compare(PHP_VERSION, '5.3', '<')) {
                     // Workaround for a bug in ErrorException::getTrace() that exists in
                     // all PHP 5.2 versions. @see http://bugs.php.net/45895
                     for ($i = count($trace) - 1; $i > 0; --$i) {
                         if (isset($trace[$i - 1]['args'])) {
                             // Re-position the arguments
                             $trace[$i]['args'] = $trace[$i - 1]['args'];
                             unset($trace[$i - 1]['args']);
                         }
                     }
                 }
             }
         }
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         if ($template = Eight::find_file('views', $template)) {
             include $template;
         }
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo Eight_Exception::text($e), "\n";
         // Exit with an error code
         exit(1);
     }
 }