oReturn = new ReturnObject(); } /** * @return ReturnObject */ public function getReturn() { $tree = debug_backtrace(); $msg = $this->oReturn->toArray(); array_shift($tree); if (ErrorCodeConstants::checkErrorCodeToLog($this->oReturn->code)) { $msg['stack'] = LogService::getStackTree(array_slice($tree, 0, 5)); LogService::error(json_encode($msg, JSON_UNESCAPED_UNICODE)); } else { $msg['stack'] = LogService::getStackTree(array_slice($tree, 0, 1)); LogService::debug(json_encode($msg, JSON_UNESCAPED_UNICODE)); } $return = $this->oReturn; $this->oReturn = new ReturnObject(); return $return; } /** * 获取运行栈 * @param $tree * @return array */ public function getContentFromTree($tree) { $return = []; $keys = ['file', 'line', 'function', 'class', 'args']; foreach($tree as $item){ $tmp = []; foreach($keys as $key){ if(array_key_exists($key, $item)){ $tmp[$key] = $item[$key]; } } $return[] = $tmp; } return $return; } /** * @param \Exception $e * @return ReturnObject */ public function getExceptionReturn(\Exception $e) { LogService::exception($e); $this->oReturn->code = ErrorCodeConstants::EXCEPTION; $this->oReturn->msg = $e->getMessage(); return $this->getReturn(); } /** * @param $data * @return $this */ public function setData($data) { $this->oReturn->data = $data; return $this; } /** * @param $msg * @return $this */ public function setMsg($msg) { $this->oReturn->msg = $msg; return $this; } /** * @param $code * @return $this */ public function setCode($code) { $this->oReturn->code = $code; return $this; } }