1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace loyalsoft;
- /**
- * Description of ResponseVo
- * 服务端消息应答实体
- * @author jgao,gwang
- */
- class Resp extends Object_ext {
- /**
- * 错误码[成功为0]
- * @var int
- */
- public $err;
- /**
- * 执行结果
- * @var Object
- */
- public $result;
- /**
- * 时间戳
- * @var int
- */
- public $ts;
- /**
- * 事件列表
- * @var array/list
- */
- public $events = array();
- /**
- * 标签[扩展用,保留]
- * @var object
- */
- public $tag;
- /**
- * 产生服务端应答
- * @param Req $req
- * @param assoc Array $ret
- * @return \ResponseVo
- */
- public static function ok($ret = null) {
- $resp = new Resp();
- $resp->err = ErrCode::ok;
- $resp->result = $ret == null ? ObjectInit() : $ret; # 避免出现null
- $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();
- $resp->err = $err;
- $resp->result = ObjectInit();
- $resp->ts = time();
- $resp->tag = ObjectInit();
- $resp->tag->errmsg = $msg;
- return $resp;
- }
- static $ext_events = array();
- public static function AddEvent($name, $arg1, $arg2) {
- self::$ext_events[] = array(
- 'name' => $name,
- 'arg1' => $arg1,
- 'arg2' => $arg2
- );
- }
- static $ext_tag = null;
- /**
- * 向返回值添加附加数据
- * @param string $name
- * @param any $value
- */
- public static function addTag($name, $value) {
- if (null == self::$ext_tag) {
- self::$ext_tag = ObjectInit();
- }
- self::$ext_tag->$name = $value;
- }
- }
|