Ejemplo n.º 1
0
 /**
  * 唯一实例
  * @return Base_Response
  */
 public static function getInstance()
 {
     if (NULL === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
    /**
     * 错误
     * @param unknown_type $e
     * @return void
     */
    public static function error($e)
    {
        $isException = is_object($e);
        if ($isException) {
            $code = $e->getCode();
            $message = $e->getMessage();
        } else {
            $code = $e;
        }
        if ($isException && $e instanceof Base_Db_Exception) {
            $code = 500;
            $message = 'Database Server Error';
        } else {
            switch ($code) {
                case 500:
                    $message = 'Internal Server Error!';
                    break;
                case 404:
                    $message = 'Not Found!';
                    break;
                case 403:
                    $message = 'Forbidden';
                    break;
                default:
                    $message = 'Error!';
            }
        }
        if (is_numeric($code) && $code > 200) {
            Base_Controller_Response_Http::setStatus($code);
        }
        $message = nl2br($message);
        print <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{$code}</title>

    <style type="text/css">
        body {
            background: #f7fbe9;
            font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana;
        }

        #error {
            background: #333;
            width: 360px;
            margin: 0 auto;
            margin-top: 100px;
            color: #fff;
            padding: 10px;

            -moz-border-radius-topleft: 4px;
            -moz-border-radius-topright: 4px;
            -moz-border-radius-bottomleft: 4px;
            -moz-border-radius-bottomright: 4px;
            -webkit-border-top-left-radius: 4px;
            -webkit-border-top-right-radius: 4px;
            -webkit-border-bottom-left-radius: 4px;
            -webkit-border-bottom-right-radius: 4px;

            border-top-left-radius: 4px;
            border-top-right-radius: 4px;
            border-bottom-left-radius: 4px;
            border-bottom-right-radius: 4px;
        }

        h1 {
            padding: 10px;
            margin: 0;
            font-size: 36px;
        }

        p {
            padding: 0 20px 20px 20px;
            margin: 0;
            font-size: 12px;
        }

        img {
            padding: 0 0 5px 260px;
        }
    </style>
</head>
<body>
    <div id="error">
        <h1>{$code}</h1>
        <p>{$message}</p>
    </div>
</body>
</html>

EOF;
    }