/** * 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 runApp() { //系统初始化 self::init(); //控制器所在路径 $actionController = APP_CONTROLLER_PATH . Route::$urlParams['controller'] . 'Controller.php'; $GLOBALS['debug'] && Debug::addTipInfo(Lang::get('_ACTION_CONTROLLER_', $actionController)); Plugin::hook('alpha.before_run_controller'); if (is_file($actionController)) { $className = Route::$urlParams['controller'] . 'Controller'; $className = (IS_MULTI_MODULES ? '' : '\\Controller') . Route::$urlParams['path'] . (IS_MULTI_MODULES ? 'Controller' . DIRECTORY_SEPARATOR : '') . "{$className}"; $className = str_replace('/', '\\', $className); $controller = new $className(); call_user_func(array($controller, "runAppController")); //运行 } else { self::montFor404Page(); if ($GLOBALS['debug']) { throwException(Lang::get('_CONTROLLER_NOT_FOUND_', APP_CONTROLLER_PATH, Route::$urlParams['controller'], str_replace('/', '\\', Route::$urlParams['path']) . Route::$urlParams['controller'])); } else { Response::show404Page(); } } //输出Debug模式的信息 self::Stop(); }
/** * 自动加载类库 * 要注意的是 使用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; }