uid = $req->uid; $resp->cmd = $req->cmd; $resp->msgid = $req->msgid; $resp->err = ErrCode::ok; $resp->result = $ret; $resp->ts = time(); $resp->tag = ObjectInit(); return $resp; } /** * * @param Req $req * @param int $err * @param string $msg 【可选】附加信息 * @return \ResponseVo */ public static function err($err, $msg = "") { $resp = new Resp(); $req = req(); $resp->uid = $req->uid; $resp->cmd = $req->cmd; $resp->msgid = $req->msgid; $resp->err = $err; $resp->result = ObjectInit(); $resp->ts = time(); $resp->tag = ObjectInit(); $resp->tag->errmsg = $msg; return $resp; } // // /** * 逻辑断言,不受系统断言状态影响,可以用于生产环境的简单判断,比如:参数非法,参数缺失等 * @param type $condition * @param int/string $err 如果是int值,则当作Errcode处理,否则当作字符串处理 */ static function assert($condition, $err) { if (!$condition) { # 断言失败 if (is_int($err)) { Resp::err($err, "Assert faild!"); } else { Resp::err(ErrCode::err_assert, $err); } trigger_error($err, E_USER_ERROR); } } /** * 接管系统的断言失败处理函数(调试用,若要检查参数是否完整,请用Resp::assert()) * 注意:方法内部依赖于GAME_ONLINE标志,若为内网调试则打开断言, * 若为线上环境则关闭断言(提升安全性和部分性能) */ static function cover_assert_handler() { assert_options(ASSERT_ACTIVE, !GAME_ONLINE); # 设置断言标志 assert_options(ASSERT_BAIL, true); assert_options(ASSERT_WARNING, false); assert_options(ASSERT_CALLBACK, array('Resp', 'my_assert_handler')); # 设置回调函数 } /** * 断言处理函数 * @param type $file * @param type $line * @param type $code * @param type $desc */ private static function my_assert_handler($file, $line, $code, $desc) { $msg = "
Assertion Failed: File '$file'
Line '$line'
Code '$code'
Desc '{$desc}'

"; Resp::errs(Err::err_assert, $msg); # 给客户端返回值 trigger_error($msg, E_USER_ERROR); } //
// }