Beispiel #1
0
 private static function setDefault()
 {
     date_default_timezone_set(Config::get('timezone'));
     //时区
     if (Config::get('session_status')) {
         session_start();
     }
 }
Beispiel #2
0
 public static function write($msg, $logdir = '')
 {
     $logdir = $logdir ? $logdir : Config::get('ERROR_LOG');
     //register_shutdown_function是从内存中执行,输入日志的地址必须为绝对路径
     $log_dir = dirname($logdir);
     if (!is_dir($log_dir)) {
         mkdir($log_dir, 0755, true);
     }
     error_log($msg, 3, $logdir . date('Y-m-d', time()) . '.log');
 }
Beispiel #3
0
 private function connect()
 {
     if (!self::$link) {
         try {
             $dsn = "mysql:local=" . Config::get('DB_HOST') . ";dbname=" . Config::get('DB_NAME');
             self::$link = new \PDO($dsn, Config::get('DB_USER'), Config::get('DB_PWD'));
             self::$link->exec('SET NAMES UTF8');
         } catch (MyHandler $e) {
             //抛出异常
         }
     }
     return self::$link;
 }
Beispiel #4
0
 public static function init()
 {
     if (Config::get('URL_MODEL') == 1) {
         //PATHINFO模式
         $ary_se = explode('/', ltrim($_SERVER['REQUEST_URI'], '/index.php/'));
         $se_count = count($ary_se);
         if ($se_count <= 1) {
             //获取默认控制器跟操作
             $controller = Config::get('DEFAULT_CONTROLLER');
             $action = Config::get('DEFAULT_ACTION');
         } else {
             $controller = $ary_se[0];
             $action = $ary_se[1];
         }
     } else {
         //普通模式
         $controller = $_GET[Config::get('VAR_CONTROLLER')];
         $action = $_GET[Config::get('VAR_ACTION')];
     }
     $controller = 'App\\Controller\\' . ucfirst($controller) . 'Controller';
     $obj = new $controller();
     $obj->{$action}();
 }
Beispiel #5
0
    /**
     * 输出错误
     * */
    private static function deal($errno, $info)
    {
        //不报NOTICE
        if (in_array($errno, array(8))) {
            return false;
        }
        $date = date('Y-m-d H:i:s', time());
        $type = self::$errAry[$errno] ? self::$errAry[$errno] : $errno;
        //异常不用转码
        $errorMsg = <<<EOF


{$type}-->

file:{$info['file']},

line:{$info['line']},

message:{$info['message']},

date:{$date}

EOF;
        $Msg = <<<EOF

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="robots" content="noindex,nofollow" />
        <style>            html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}

            html { background: #eee; padding: 10px }
            img { border: 0; }
            #sf-resetcontent { width:970px; margin:0 auto; }
                        .sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }
            .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
            .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
            .sf-reset .clear_fix { display:inline-block; }
            .sf-reset * html .clear_fix { height:1%; }
            .sf-reset .clear_fix { display:block; }
            .sf-reset, .sf-reset .block { margin: auto }
            .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
            .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
            .sf-reset strong { font-weight:bold; }
            .sf-reset a { color:#6c6159; cursor: default; }
            .sf-reset a img { border:none; }
            .sf-reset a:hover { text-decoration:underline; }
            .sf-reset em { font-style:italic; }
            .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
            .sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; }
            .sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; }
            .sf-reset .exception_message { margin-left: 3em; display: block; }
            .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
            .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
                -webkit-border-bottom-right-radius: 16px;
                -webkit-border-bottom-left-radius: 16px;
                -moz-border-radius-bottomright: 16px;
                -moz-border-radius-bottomleft: 16px;
                border-bottom-right-radius: 16px;
                border-bottom-left-radius: 16px;
                border-bottom:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
            }
            .sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px;
                -webkit-border-top-left-radius: 16px;
                -webkit-border-top-right-radius: 16px;
                -moz-border-radius-topleft: 16px;
                -moz-border-radius-topright: 16px;
                border-top-left-radius: 16px;
                border-top-right-radius: 16px;
                border-top:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
                overflow: hidden;
                word-wrap: break-word;
            }
            .sf-reset a { background:none; color:#868686; text-decoration:none; }
            .sf-reset a:hover { background:none; color:#313131; text-decoration:underline; }
            .sf-reset ol { padding: 10px 0; }
            .sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;
                -webkit-border-radius: 10px;
                -moz-border-radius: 10px;
                border-radius: 10px;
                border: 1px solid #ccc;
            }
        </style>
    </head>
    <body>
                    <div id="sf-resetcontent" class="sf-reset">
                <h1>{$type}</h1>
                                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">1/1</span>
                            <span class="exception_title">{$info['file']} line {$info['line']}</a>:</span>
                            <span class="exception_message">{$info['message']}</span>                        
EOF;
        if (in_array($errno, array(1, 4, 256, 'Exception'))) {
            ob_start();
            debug_print_backtrace();
            $trace = ob_get_clean();
            $errorMsg .= <<<EOF
trace:{$trace}

EOF;
            $Msg .= <<<EOF
<span class="exception_message">trace:{$trace}</span>
EOF;
        }
        $Msg .= <<<EOF
</h2>
<div class="block">
<ol class="traces list_exception">
\t<li> in {$info['file']} line {$info['line']} </li>
</ol>
</div>
</div>
</body>
</html>
EOF;
        $log_dir = dirname(Config::get('ERROR_LOG'));
        if (!is_dir($log_dir)) {
            mkdir($log_dir, 0755, true);
        }
        $filename = Config::get('ERROR_LOG') . date('Y-m-d', time()) . '.log';
        error_log($errorMsg, 3, $filename);
        //是否显示错误到屏幕
        if (Config::get('ERROR_SHOW')) {
            in_array($errno, array(1, 4, 256)) ? die($Msg) : '';
            echo $Msg;
        } else {
            in_array($errno, array(1, 4, 256)) ? die : '';
        }
    }