Example #1
0
 /**
  * 生成PDO实例
  *
  * @throws \ErrorException
  * @return string
  */
 private function generateDsn()
 {
     $config = $this->config;
     if (\method_exists($this, $config['type'])) {
         try {
             return \call_user_func_array([$this, $config['type']], [$config]);
         } catch (\PDOException $e) {
             Error::fatal($e->getMessage(), $e->getCode());
         }
     } else {
         throw new \ErrorException('数据库类型 [' . $config['type'] . '] 不存在');
     }
 }
Example #2
0
 /**
  * 输出错误
  *
  * @param string $code 错误编码
  * @param string $msg 错误消息
  * @param string $name 值名称
  * @param array  $option
  * @param bool   $strict 是否严格模式
  *
  * @return null
  */
 private static function error($code, $msg, $name, array $option, $strict)
 {
     $field = isset($option['_desc']) ? $name . ':' . $option['_desc'] : $name;
     $line = isset($option['_line']) ? ' At line: ' . $option['_line'] : '';
     $msg = '[' . $field . '] ' . $msg . '.' . $line;
     if ($strict) {
         Error::msg('inputIll', $msg, ['field' => $name, 'code' => $code]);
     } elseif (RUN_MODE !== 'production') {
         Error::notice('inputIll', $msg);
     }
     return null;
 }
Example #3
0
 /**
  * 输出解析中的错误
  *
  * @param $code
  * @param $msg
  */
 protected function error($code, $msg)
 {
     Error::fatal($code, $msg . ' [in file: ' . $this->file . ' on line: ' . $this->line . '].');
 }
Example #4
0
 /**
  * 设置请求返回状态,默认为200
  *
  * @param int   $status 状态码
  * @param array $param 请求传递的参数
  * @param bool  $error 是否判定为错误
  */
 public function status($status, $param = [], $error = true)
 {
     \header('Status: ' . $status);
     if ($status >= 400 && $error) {
         self::$taskSuccess = false;
         Error::fatal($status, '', $param);
     }
 }
Example #5
0
 /**
  * 输出xml
  */
 protected static function xml()
 {
     \header('Content-type: application/xml; charset=' . \Config::CHARSET);
     $header = Error::prepareHeader();
     $header = array_merge($header, Action::getHeaderStore());
     $header['data'] = Action::getDataStore();
     $content = self::array2xml($header, new \SimpleXMLElement('<root></root>'))->asXML();
     return $content;
 }