Beispiel #1
0
 /**
  * 系统调用内容输出函数(请勿自行执行)
  */
 public static function _output_body()
 {
     # 发送header数据
     HttpIO::send_headers();
     if (IS_DEBUG && isset($_REQUEST['debug']) && class_exists('Profiler', true)) {
         # 调试打开时不缓存页面
         HttpIO::set_cache_header(0);
     }
     # 执行注册的关闭方法
     ob_start();
     Core::event_trigger('system.shutdown');
     $output = ob_get_clean();
     # 在页面输出前关闭所有的连接
     Core::close_all_connect();
     # 输出内容
     echo Core::$output, $output;
 }
Beispiel #2
0
 /**
  * 页面跳转
  *
  * @param  string  $url 跳转的URL
  * @param  integer $code 状态 : 301, 302, etc
  * @return void
  * @uses   Core::url
  * @uses   HttpIO::send_headers
  */
 public static function redirect($url, $code = 302)
 {
     if ($url[0] !== '/' && strpos($url, '://') === false) {
         // Make the URI into a URL
         $url = Core::url($url);
     }
     // Set the response status
     HttpIO::$status = $code;
     // Set the location header
     HttpIO::$headers['Location'] = $url;
     // Send headers
     HttpIO::send_headers();
     // Stop execution
     exit;
 }
Beispiel #3
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  *
  * @param string/Exception $msg
  */
 public static function show_500($msg = null, $error_code = 500)
 {
     # 将输出全部清除
     static::close_buffers(false);
     \HttpIO::status($error_code);
     \HttpIO::send_headers();
     if (null === $msg) {
         $msg = \__('Internal Server Error');
     }
     if (\IS_DEBUG && \class_exists('\\DevException', false)) {
         if ($msg instanceof \Exception) {
             throw $msg;
         } else {
             throw new \Exception($msg, 0);
         }
     }
     if (\IS_CLI) {
         echo $msg . \CRLF;
         exit;
     }
     try {
         $view = new \View('error/500');
         $error = '';
         if ($msg instanceof \Exception) {
             $error .= 'Msg :' . $msg->getMessage() . \CRLF . "Line:" . $msg->getLine() . \CRLF . "File:" . static::debug_path($msg->getFile());
         } else {
             $error .= $msg;
         }
         $view->error = $error;
         $view->render(true);
     } catch (\Exception $e) {
         list($REQUEST_URI) = \explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = \htmlspecialchars(\rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . \CRLF . '<html>' . \CRLF . '<head>' . \CRLF . '<title>' . \__('Internal Server Error') . '</title>' . \CRLF . '</head>' . \CRLF . '<body>' . \CRLF . '<h1>' . \__('Internal Server Error') . '</h1>' . \CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . \CRLF . '<hr>' . \CRLF . $_SERVER['SERVER_SIGNATURE'] . \CRLF . '<!-- ' . \htmlspecialchars($msg) . ' -->' . \CRLF . '</body>' . \CRLF . '</html>';
     }
     exit;
 }
Beispiel #4
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    self::exception_text
  * @param   Exception $e object exception object
  * @return  bool
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         if (IS_CLI) {
             $str = self::exception_text($e) . "\n" . $e->__toString() . "\n";
             if ($return) {
                 return $str;
             } else {
                 echo $str;
             }
             return true;
         }
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             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/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if (true !== $return) {
             Core::close_buffers(false);
             if ($e->getCode() === E_PAGE_NOT_FOUND) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 400 && $e->getCode() <= 410) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 500 && $e->getCode() <= 510) {
                 HttpIO::$status = 404;
             } else {
                 HttpIO::$status = 500;
             }
             @header('Content-Type:text/html;charset=utf-8');
             HttpIO::send_headers();
         }
         ob_start();
         include Core::find_file('views', self::$template);
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return true;
     } catch (Exception $e) {
         ob_get_level() and ob_clean();
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses	Kohana::exception_text
  * @param   object   exception object
  * @return  boolean
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (isset(self::$php_errors[$code])) {
             $code = self::$php_errors[$code];
         }
         // Create a text version of the exception
         $error = self::exception_text($e);
         if (IS_CLI) {
             // Just display the text of the exception
             echo "\n{$error}\n";
             return TRUE;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             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/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if ($return !== true) {
             Core::close_buffers(FALSE);
         }
         if ($e->getCode() == 43) {
             HttpIO::$status = 404;
         } else {
             HttpIO::$status = 500;
         }
         HttpIO::send_headers();
         // Start an output buffer
         ob_start();
         // Include the exception HTML
         include Core::find_file('views', self::$template);
         // Display the contents of the output buffer
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return TRUE;
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
Beispiel #6
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('ErrException', false)) {
         if ($msg instanceof Exception) {
             throw $msg;
         } else {
             throw new Exception($msg, 0);
         }
     }
     if (IS_CLI) {
         echo $msg . CRLF;
         exit;
     }
     try {
         $view = new View('error/500');
         $error = '';
         if ($msg instanceof Exception) {
             $error .= 'Msg :' . $msg->getMessage() . CRLF . "Line:" . $msg->getLine() . CRLF . "File:" . Core::debug_path($msg->getFile());
         } else {
             $error .= $msg;
         }
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>' . __('Internal Server Error') . '</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr>' . CRLF . $_SERVER['SERVER_SIGNATURE'] . CRLF . '</body>' . CRLF . '</html>';
     }
     # 执行注册的shutdown方法,并忽略输出的内容
     ob_start();
     Core::run_shutdown_function();
     ob_end_clean();
     exit;
 }
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses	Kohana::exception_text
  * @param   object   exception object
  * @return  boolean
  */
 public static function exception_handler(\Exception $e, $return = false)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (isset(static::$php_errors[$code])) {
             $code = static::$php_errors[$code];
         }
         // Create a text version of the exception
         $error = static::exception_text($e);
         if (\IS_CLI) {
             echo "\n{$error}\n";
             return true;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($return !== true) {
             \Core::close_buffers(false);
         }
         if ($e->getCode() == 43 || $e->getCode() == 404) {
             \HttpIO::status(404);
         } else {
             \HttpIO::status(500);
         }
         \HttpIO::send_headers();
         \ob_start();
         include \Core::find_view(static::$template);
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return true;
     } catch (\Exception $e) {
         // Clean the output buffer if one exists
         \ob_get_level() && \ob_clean();
         // Display the exception text
         echo static::exception_text($e), "\n";
         exit(1);
     }
 }