Example #1
0
 /**
  * Get the result of output
  *
  * @return array
  */
 private function getResult() : array
 {
     if ($this->exception) {
         $errcode = $this->exception->getMessage();
         if ($pos = strpos($errcode, ' ')) {
             $errcode = substr($errcode, 0, $pos);
         }
         if (!preg_match('/^[a-zA-Z0-9\\.\\-_]{1,50}$/', $errcode)) {
             //普通的错误信息不能传到前端
             $errcode = self::STATUS_FATAL;
         }
         $result = array('err' => $errcode);
         if ($errcode == self::STATUS_INPUT) {
             //输入check错误时,可以带些数据
             $result['data'] = $this->outputs;
             Logger::debug('input data error:%s', print_r($result['data'], true));
         }
     } elseif ($this->error) {
         $result = array('err' => self::STATUS_FATAL);
     } else {
         $result = array('err' => self::STATUS_OK, 'data' => $this->outputs);
     }
     foreach ($this->results as $key => $value) {
         if (!isset($result[$key])) {
             $result[$key] = $value;
         }
     }
     return $result;
 }
Example #2
0
 /**
  *  Inner Exception handler
  *
  * @param Exception $ex
  */
 public function exceptionHandler($ex)
 {
     restore_exception_handler();
     $errcode = $ex->getMessage();
     $errmsg = sprintf('caught exception, errcode:%s, trace: %s', $errcode, $ex->__toString());
     if ($pos = strpos($errcode, ' ')) {
         $errcode = substr($errcode, 0, $pos);
     }
     $this->endStatus = $errcode;
     if ($this->isUserErr($errcode)) {
         Logger::trace($errmsg);
     } else {
         Logger::fatal($errmsg);
     }
 }