Example #1
0
 /**
  * 框架autoloader
  * @param string $classname 要加载的类名
  */
 public static function loader($classname)
 {
     if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $classname)) {
         exit;
     }
     if (isset(self::$coreClass[$classname])) {
         $path = '';
         $filename = $classname;
         //默认文件名称和类名称相同
         if (!is_array(self::$coreClass[$classname])) {
             $path = self::$coreClass[$classname];
         } else {
             if (isset(self::$coreClass[$classname]['path'])) {
                 $path = implode('', self::$coreClass[$classname]['path']);
             }
             if (isset(self::$coreClass[$classname]['classname'])) {
                 $filename = self::$coreClass[$classname]['filename'];
                 //用手工配置的文件名称覆盖默认的
             }
             if (isset(self::$coreClass[$classname]['postfix'])) {
                 $filename .= self::$coreClass[$classname]['postfix'];
             }
         }
         self::includeFile($path, $filename);
     } else {
         /**
          * 对于外部使用Dagger,不要去找文件结尾为Controller、
          * DB或者其它任何没有被加载的文件
          */
         if (preg_grep('/.*?Controller$/', array($classname))) {
             self::includeFile(DAGGER_PATH_APP_CTL, $classname);
         } else {
             if (preg_grep('/.*?ModelDB$/', array($classname))) {
                 self::includeFile(DAGGER_PATH_MODEL . 'db/', $classname);
             } else {
                 if (preg_grep('/.*?Config$/', array($classname))) {
                     self::includeFile(DAGGER_PATH_CONFIG, $classname);
                 } else {
                     if (preg_grep('/.*?Pagelet$/', array($classname))) {
                         self::includeFile(DAGGER_PATH_APP_PLT, $classname);
                     } else {
                         if (defined('DAGGER_PATH_APP_MODEL') && file_exists(DAGGER_PATH_APP_MODEL . "{$classname}.php")) {
                             if (file_exists(DAGGER_PATH_MODEL . "{$classname}.php")) {
                                 BaseModelLog::sendLog(90107, "{$classname}.php文件在/app/" . htmlspecialchars(Configure::$app, ENT_QUOTES, 'UTF-8') . "/model目录和/model目录重名", '', BaseModelLog::ERROR_MODEL_ID_PHP);
                                 BaseModelMessage::showError("{$classname}.php文件在/app/" . htmlspecialchars(Configure::$app, ENT_QUOTES, 'UTF-8') . "/model目录和/model目录重名");
                             }
                             self::includeFile(DAGGER_PATH_APP_MODEL, $classname);
                         } else {
                             self::includeFile(DAGGER_PATH_MODEL, $classname);
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
function daggerExceptionHandler($exception)
{
    $errormsg = $exception->getMessage();
    $errno = $exception->getCode();
    $sendmsg = (empty($_SERVER['REQUEST_URI']) ? empty($_SERVER['SCRIPT_FILENAME']) ? '' : '(' . $_SERVER['SCRIPT_FILENAME'] . ')' : '(' . $_SERVER['REQUEST_URI'] . ')') . $errormsg;
    //记录到监控中心
    switch (get_class($exception)) {
        case 'BaseModelDBException':
            BaseModelLog::sendLog($errno, $sendmsg, '', BaseModelLog::ERROR_MODEL_ID_DB);
            break;
        case 'BaseModelMCException':
            BaseModelLog::sendLog($errno, $sendmsg, '', BaseModelLog::ERROR_MODEL_ID_MC);
            break;
        case 'BaseModelHTTPException':
            BaseModelLog::sendLog($errno, $sendmsg, '', BaseModelLog::ERROR_MODEL_ID_HTTP);
            break;
        case 'BaseModelS3Exception':
            BaseModelLog::sendLog($errno, $sendmsg, '', BaseModelLog::ERROR_MODEL_ID_S3);
            break;
        default:
            BaseModelLog::sendLog($errno, $sendmsg, '', BaseModelLog::ERROR_MODEL_ID_DEFAULT);
            break;
    }
    defined('DAGGER_DEBUG') && BaseModelCommon::debug('[errro code] ' . $errno . ' [errro msg] ' . $errormsg . ' [详细说明]:https://github.com/wxkingstar/dagger/wiki/' . $errno, 'dagger_error');
    if (!defined('DAGGER_DEBUG') || defined('DAGGER_ENV') && DAGGER_ENV === 'product') {
        BaseModelMessage::showError('抱歉让您看到这个页面');
    } else {
        if (defined('QUEUE') || isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
            BaseModelMessage::showError($errormsg, BaseModelException::$data, $errno);
        } else {
            $trace = $exception->getTrace();
            $tracemsg = array();
            $pos = 0;
            foreach ($trace as $k => $error) {
                if (strpos($error['function'], "smarty_function_") === 0) {
                    $errormsg = 'smarty插件:' . substr($error['function'], 16) . $errormsg;
                    $pos = false;
                    defined('DAGGER_DEBUG') && BaseModelCommon::debug($errormsg, 'dagger_error');
                }
                if (!isset($error['line']) && $pos === 0) {
                    $pos = $k;
                }
                if (!empty($error['function'])) {
                    $fun = '';
                    if (!empty($error['class'])) {
                        $fun .= $error['class'] . $error['type'];
                    }
                    $fun .= $error['function'] . '(';
                    if (!empty($error['args'])) {
                        $mark = '';
                        foreach ($error['args'] as $arg) {
                            //由于smarty和call_user方法会出现超大对象或数组传入,导致报错页面崩溃,所以直接跳过参数解析输出
                            if (stripos($error['function'], 'smarty') === 0 || stripos($error['function'], 'call_user') === 0) {
                                continue;
                            }
                            $fun .= $mark;
                            if (is_array($arg)) {
                                $fun .= var_export($arg, true);
                            } else {
                                if (is_bool($arg)) {
                                    $fun .= $arg ? 'true' : 'false';
                                } else {
                                    if (is_int($arg) || is_float($arg)) {
                                        $fun .= $arg;
                                    } else {
                                        if (is_null($arg)) {
                                            $fun .= 'NULL';
                                        } else {
                                            $fun .= '\'' . BaseModelException::daggerHtmlspecialchars(BaseModelException::daggerClear($arg)) . '\'';
                                        }
                                    }
                                }
                            }
                            $mark = ', ';
                        }
                    }
                    $fun .= ')';
                    $error['function'] = $fun;
                }
                $tracemsg[] = array('file' => isset($error['file']) ? str_replace(array(DAGGER_PATH_ROOT, '\\'), array('', '/'), $error['file']) : '', 'line' => isset($error['line']) ? $error['line'] : '', 'function' => $error['function']);
            }
            $throwPhpCode = file($exception->getFile());
            $tracemsg = array_merge(array(array('file' => str_replace(array(DAGGER_PATH_ROOT, '\\'), array('', '/'), $exception->getFile()), 'line' => $exception->getLine(), 'function' => $throwPhpCode[$exception->getLine() - 1])), $tracemsg);
            defined('DAGGER_DEBUG') && BaseModelCommon::debug(array_merge(array(array('File', 'Line', 'Function')), $tracemsg), 'dagger_error_trace');
            if ($pos > 0) {
                $errorFileCode = array_slice(file($tracemsg[$pos]['file']), $tracemsg[$pos]['line'] > 6 ? $tracemsg[$pos]['line'] - 7 : 0, 13);
                $tracemsg[$pos]['function'] = '<pre class="brush: php; toolbar : false; highlight: ' . $tracemsg[$pos]['line'] . '; first-line: ' . ($tracemsg[$pos]['line'] > 6 ? $tracemsg[$pos]['line'] - 6 : 1) . '">' . implode('', $errorFileCode) . '</pre>';
            }
            $traceTable = '';
            if (is_array($tracemsg) && !empty($tracemsg)) {
                $traceTable .= '<table cellpadding="5" cellspacing="1" width="100%" class="table">';
                $traceTable .= '<tr class="bg2"><th width="249px">File</th><th width="44px">Line</th><th width="629px">Function</th></tr>';
                foreach ($tracemsg as $k => $msg) {
                    $traceTable .= '<tr class="' . ($pos > 0 && $k == $pos ? 'bg3' : 'bg1') . '">';
                    $traceTable .= '<td>' . $msg['file'] . '</td>';
                    $traceTable .= '<td>' . $msg['line'] . '</td>';
                    $traceTable .= '<td>' . $msg['function'] . '</td>';
                    $traceTable .= '</tr>';
                }
                $traceTable .= '</table>';
            }
            BaseModelDebug::showTrace($errno, $errormsg, $traceTable);
        }
    }
}
Example #3
0
 private static function _checkFields($data)
 {
     empty(self::$fieldsArr) && (self::$fieldsArr = array_flip(explode(',', $_GET['fields'])));
     $newData = array();
     if (!isset($data['0'])) {
         //一维数组
         $newData = array_intersect_key($data, self::$fieldsArr);
     } else {
         // 多维数组
         if (is_array($data['0']['data']) && count($data['0']['data'] > 0)) {
             foreach ($data as $kk => $vv) {
                 $data[$kk]['data'] = array_map(array('self', '_checkFields'), $vv['data']);
             }
             $newData = $data;
         } else {
             //二维数组,要求数组里每一个一维数组的键名都是一样的
             foreach ($data as $kk => $vv) {
                 $newData[$kk] = array_intersect_key($vv, self::$fieldsArr);
             }
         }
     }
     return $newData;
 }