/** * 输出数据 * */ public function display() { header('Content-Type: application/json;charset=' . Config::get('default_charset')); if ($GLOBALS['debug']) { $sql = Debug::getSqls(); if (Config::get('dump_use_php_console')) { $sql && \Foundation\dumpUsePHPConsole($sql, 'sql'); \Foundation\dumpUsePHPConsole(Debug::getTipInfo(), 'tipInfo'); \Foundation\dumpUsePHPConsole(Debug::getIncludeFiles(), 'includeFile'); } else { if (isset($sql[0])) { $this->args['sql'] = implode($sql, ', '); } } } else { $deBugLogData = \Foundation\dump('', 1); if (!empty($deBugLogData)) { Config::get('dump_use_php_console') ? \Foundation\dumpUsePHPConsole($deBugLogData, 'debug') : ($this->args['debug_info'] = $deBugLogData); } } exit(json_encode($this->args, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0)); }
/** * Debug模式记录查询语句显示到控制台 * * @param string $type 查询的类型 * @param string $tableName 查询的Collection * @param array $condition 条件 * @param array $options 额外参数 */ private function debugLogSql($type = 'Query', $tableName, $condition = array(), $options = array()) { if ($GLOBALS['debug']) { Debug::addTipInfo(sprintf("[MongoDB {$type}] Collection: %s, Condition: %s, Other: %s", $this->getDbName() . ".{$tableName}", json_encode($condition, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0), json_encode($options, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0)), 2); } }
/** * 程序中并输出调试信息 * */ public static function Stop() { //输出Debug模式的信息 if ($GLOBALS['debug']) { header('Content-Type:text/html; charset=' . Config::get('default_charset')); Debug::stop(); } else { $deBugLogData = dump('', 1); if (!empty($deBugLogData)) { Config::get('dump_use_php_console') ? \Foundation\dumpUsePHPConsole($deBugLogData) : (require ALPHA_PATH . DIRECTORY_SEPARATOR . 'Foundation' . DIRECTORY_SEPARATOR . 'ConsoleLog.php'); } ALPHA_OB_START && ob_end_flush(); exit; } }
/** * 自动加载类库 * 要注意的是 使用autoload的时候 不能手动抛出异常 * 因为在自动加载静态类时手动抛出异常会导致自定义的致命错误捕获机制和自定义异常处理机制失效 * 而 new Class 时自动加载不存在文件时,手动抛出的异常可以正常捕获 * 这边即使文件不存在时没有抛出自定义异常也没关系,因为自定义的致命错误捕获机制会捕获到错误 * * @params string $className */ public static function autoloadComposerAdditional($className) { $GLOBALS['debug'] && \Foundation\Debug::addTipInfo(\Foundation\Lang::get('_DEBUG_ADD_CLASS_TIP_', $className), 1); //在debug中显示包含的类 }
/** * 预处理语句 * * @param string $sql 要预处理的sql语句 * @param \PDO $link * @param bool $resetParams * * @return \PDOStatement */ public function prepare($sql, $link = null, $resetParams = true) { $resetParams && $this->reset(); is_null($link) && ($link = $this->wlink); if ($GLOBALS['debug']) { $bindParams = $this->bindParams; foreach ($bindParams as $key => $val) { $bindParams[$key] = str_replace('\\\\', '\\', addslashes($val)); } Debug::addTipInfo(vsprintf(str_replace('%s', "'%s'", $sql), $bindParams), 2); } $sqlParams = array(); foreach ($this->bindParams as $key => $val) { $sqlParams[] = ':param' . $key; } $tipSql = $sql; $sql = vsprintf($sql, $sqlParams); $stmt = $link->prepare($sql); //pdo默认情况prepare出错不抛出异常只返回Pdo::errorInfo if ($stmt === false) { $error = $link->errorInfo(); $bindParams = $this->bindParams; foreach ($bindParams as $key => $val) { $bindParams[$key] = str_replace('\\\\', '\\', addslashes($val)); } \Foundation\throwException('Pdo Prepare Sql error! ,【Sql : ' . vsprintf(str_replace('%s', "'%s'", $tipSql), $bindParams) . '】,【Code:' . $link->errorCode() . '】, 【ErrorInfo!:' . $error[2] . '】 <br />'); } else { foreach ($this->bindParams as $key => $val) { is_int($val) ? $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_INT) : $stmt->bindValue(':param' . $key, $val, \PDO::PARAM_STR); } return $stmt; } return false; }