oReturn = new ReturnObject(); $this->request = Request::instance(); } /** * @return ReturnObject */ public function getReturn() { $tree = debug_backtrace(); $msg = $this->oReturn->toArray(); array_shift($tree); unset($msg['data']); if (ErrorCodeConstants::checkErrorCodeToLog($this->oReturn->code)) { $msg['debug'] = $this->getContentFromTree(array_slice($tree, 0, 5)); LogService::error(json_encode($msg, JSON_UNESCAPED_UNICODE)); } else { $msg['debug'] = $this->getContentFromTree(array_slice($tree, 0, 1)); LogService::debug(json_encode($msg, JSON_UNESCAPED_UNICODE)); } if (!$this->oReturn->msg) { $this->oReturn->msg = ArrayHelper::arrayGet(ErrorCodeConstants::$desc, $this->oReturn->code); } $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) { if(ArrayHelper::arrayGet($item, 'file')){ $file = pathinfo($item['file']); $item['file'] = $file['basename']; } if(ArrayHelper::arrayGet($item, 'class')){ $path = explode('\\', $item['class']); $item['class'] = array_pop($path); } $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 = $e->getCode(); $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; } }