一个显示效果非常不错的PHP错误、异常处理类(3)

$errorMsg = str_replace(SITE_PATH, '', $errorMsg);
  ob_end_clean();
  $host = $_SERVER['HTTP_HOST'];
  $title = $type == 'db' ? 'Database' : 'System';
  echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>$host - $title Error</title>
 <meta http-equiv="Content-Type" content="text/html; charset={$_G['config']['output']['charset']}" />
 <meta content="NOINDEX,NOFOLLOW,NOARCHIVE" />
 <style type="text/css">
 <!--
 body { background-color: white; color: black; font: 9pt/11pt verdana, arial, sans-serif;}
 #container {margin: 10px;}
 #message {width: 1024px; color: black;}
 .red {color: red;}
 a:link {font: 9pt/11pt verdana, arial, sans-serif; color: red;}
 a:visited {font: 9pt/11pt verdana, arial, sans-serif; color: #4e4e4e;}
 h1 {color: #FF0000; font: 18pt "Verdana"; margin-bottom: 0.5em;}
 .bg1 {background-color: #FFFFCC;}
 .bg2 {background-color: #EEEEEE;}
 .table {background: #AAAAAA; font: 11pt Menlo,Consolas,"Lucida Console"}
 .info {
  background: none repeat scroll 0 0 #F3F3F3;
  border: 0px solid #aaaaaa;
  border-radius: 10px 10px 10px 10px;
  color: #000000;
  font-size: 11pt;
  line-height: 160%;
  margin-bottom: 1em;
  padding: 1em;
 }

.help {
  background: #F3F3F3;
  border-radius: 10px 10px 10px 10px;
  font: 12px verdana, arial, sans-serif;
  text-align: center;
  line-height: 160%;
  padding: 1em;
 }

.sql {
  background: none repeat scroll 0 0 #FFFFCC;
  border: 1px solid #aaaaaa;
  color: #000000;
  font: arial, sans-serif;
  font-size: 9pt;
  line-height: 160%;
  margin-top: 1em;
  padding: 4px;
 }
 -->
 </style>
</head>
<body>
<div>
<h1>$title Error</h1>
<div>$errorMsg</div>
EOT;
  if (!empty($phpMsg)) {
   echo '<div>';
   echo '<p><strong>PHP Debug</strong></p>';
   echo '<table cellpadding="5" cellspacing="1"><tbody>';
   if (is_array($phpMsg)) {
    echo '<tr><td>No.</td><td>File</td><td>Line</td><td>Code</td></tr>';
    foreach ($phpMsg as $k => $msg) {
     $k++;
     echo '<tr>';
     echo '<td>' . $k . '</td>';
     echo '<td>' . $msg['file'] . '</td>';
     echo '<td>' . $msg['line'] . '</td>';
     echo '<td>' . $msg['function'] . '</td>';
     echo '</tr>';
    }
   } else {
    echo '<tr><td><ul>' . $phpMsg . '</ul></td></tr>';
   }
   echo '</tbody></table></div>';
  }
  echo <<<EOT
</div>
</body>
</html>
EOT;
  exit();
 }
}

/**
 * DB异常类
 *
 * @author blog.snsgou.com
 */
class DbException extends Exception {

protected $sql;
 protected $dbConfig; // 当前数据库配置信息

public function __construct($message, $code = 0, $sql = '', $dbConfig = array()) {
  $this->sql = $sql;
  $this->dbConfig = $dbConfig;
  parent::__construct($message, $code);
 }

public function getSql() {
  return $this->sql;
 }

public function getDbConfig() {
  return $this->dbConfig;
 }
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/35a1b73bbdf99f78203ebe7ebfa9bba4.html