예제 #1
0
파일: Mysql.php 프로젝트: ZhuJingfa/HuiLib
 /**
  * 增加一条日志信息
  *
  * @param string $message
  * @param bool $trace 是否添加调试信息
  */
 public function add($message, $isTrace = TRUE)
 {
     $logInfo = array('log' => $message);
     if ($isTrace) {
         $trace = self::getDebugTrace(2);
         //过滤两级
         if (!empty($trace)) {
             //保留最近一条执行路径
             $logInfo['trace'] = array_shift($trace);
         }
     }
     $logInstance = SystemLog::create()->createRow();
     $logInstance['UrlNow'] = Param::getRequestUrl();
     $logInstance['Type'] = $this->type;
     $logInstance['Identify'] = $this->identify;
     $logInstance['Info'] = json_encode($logInfo);
     $request = Front::getInstance()->getRequest();
     $logInstance['Package'] = $request->getPackageRouteSeg();
     $logInstance['Control'] = $request->getControllerRouteSeg();
     $logInstance['Action'] = $request->getActionRouteSeg();
     $logInstance['Uid'] = $this->getLoginUid();
     $logInstance['CreateTime'] = DateTime::format();
     $this->buffer[] = $logInstance;
     $this->iter++;
     //超出缓存允许长度、超出缓存生命期输出到磁盘
     if ($this->needFulsh()) {
         $this->flush();
     }
     return $this;
 }
예제 #2
0
 private function test()
 {
     echo $encoding = \HuiLib\Helper\Param::server('fdasfdsa', \HuiLib\Helper\Param::TYPE_BOOL);
     var_dump($encoding);
     echo $encoding = \HuiLib\Helper\Param::server('fdasfdsa', \HuiLib\Helper\Param::TYPE_STRING);
     var_dump($encoding);
 }
예제 #3
0
 /**
  * 检验安全校验码
  */
 public function checkState()
 {
     $state = Param::get('state', Param::TYPE_STRING);
     if (!isset($_SESSION['tmpOpenConnectState']) || $_SESSION['tmpOpenConnectState'] != $state) {
         return FALSE;
     }
     return TRUE;
 }
예제 #4
0
파일: Output.php 프로젝트: ZhuJingfa/HuiLib
 /**
  * 开启输出控制
  */
 public function obstart()
 {
     $encoding = Param::server('HTTP_ACCEPT_ENCODING', Param::TYPE_STRING);
     $accept = in_array('gzip', explode(',', $encoding));
     if ($this->gzipEnable && function_exists('ob_gzhandler') && $accept) {
         ob_start('ob_gzhandler');
     } else {
         $this->gzipEnable = FALSE;
         ob_start();
     }
 }
예제 #5
0
파일: Http.php 프로젝트: ZhuJingfa/HuiLib
 /**
  * 规范访问重写请求Url
  */
 protected function formatRequestURI()
 {
     //访问主域名
     if ($this->scriptUrl == '/') {
         return true;
     }
     //双//等处理
     if (String::exist($this->scriptUrl, '//')) {
         $this->scriptUrl = preg_replace('/\\/+/is', '/', $this->scriptUrl);
     }
     // 重写请求Url以横杠结尾时处理
     if (String::substr($this->scriptUrl, -1, 1) == '/') {
         $this->scriptUrl = String::substr($this->scriptUrl, 0, -1);
     }
     //有更改过scriptUrl,重新定位
     if ($this->scriptUrl != Param::getScriptUrl()) {
         $queryString = Param::getQueryString();
         Header::redirect($this->scriptUrl . ($queryString ? '?' . $queryString : ''));
     }
     return true;
 }
예제 #6
0
파일: Base.php 프로젝트: ZhuJingfa/HuiLib
 /**
  * 生成一个头像储存路径
  * 
  * 需要将size替换为相应规格号
  */
 protected function getAvatarPath($meta)
 {
     if (empty($meta['size']) || empty($meta['type']) || empty($meta['name']) || empty($meta['uid'])) {
         throw new Exception(Front::getInstance()->getHuiLang()->_('cdn.upload.files.error'));
     }
     $uid = $meta['uid'];
     $config = $this->getConfig();
     $type = Param::post('type', Param::TYPE_STRING);
     //替换为10位,刚好10亿 1000,000,000
     $uidStr = sprintf("%010d", $uid);
     $filePath = $config['save_path'] . $type . SEP . substr($uidStr, 0, 4) . SEP . substr($uidStr, 4, 3) . SEP . substr($uidStr, 7, 3) . SEP;
     //创建目录
     if (!is_dir($filePath)) {
         mkdir($filePath, 0777, TRUE);
     }
     $ext = $this->getExt($meta['name']);
     $file = $filePath . '{size}' . $ext;
     $result = array();
     $result['file'] = $file;
     $result['url'] = str_ireplace(SEP, URL_SEP, str_ireplace($config['save_path'], '', $file));
     return $result;
 }
예제 #7
0
 /**
  * 发送Json结果数据
  * @param array $result 结果
  */
 protected function sendJson($result)
 {
     //编码json,之所以没有发送application/json的头,因为统一便于前台处理,特别是发生错误的时候。
     $json = json_encode($result);
     $callback = \HuiLib\Helper\Param::get('callback', \HuiLib\Helper\Param::TYPE_STRING);
     if ($callback) {
         $json = $callback . "({$json})";
     }
     //如果通过iframe传输,不同于jsonp,因为有时是文件上传
     if (Param::get('iframe', Param::TYPE_BOOL)) {
         $json = '<script type="text/javascript">window.top.' . $json . '</script>';
     }
     echo $json;
     die;
 }
예제 #8
0
 protected function preCheck()
 {
     try {
         $huiLang = Front::getInstance()->getHuiLang();
         $appId = Param::post('app_id', Param::TYPE_STRING);
         if (!$appId) {
             return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.app_id.null'));
         }
         if (empty($_FILES)) {
             return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.empty'));
         }
         $secret = $this->getAppSecret($appId);
         $post = $this->remapPostArray($_POST);
         //字符安全解密
         if (!Utility::decrypt($post, $secret)) {
             return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.decode.failed'));
         }
         $config = $this->getConfig();
         //上传文件校验处理 一个有错,全部终止
         foreach ($_FILES as $key => $file) {
             $meta = Param::post($key, Param::TYPE_ARRAY);
             if (empty($meta['size']) || empty($meta['type']) || empty($meta['name']) || empty($meta['sha1'])) {
                 return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.error'));
             }
             if ($file['error'] || $file['size'] != $meta['size'] || sha1_file($file['tmp_name']) != $meta['sha1']) {
                 return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.finger.print.error'));
             }
             if (!empty($config['max_filesize']) && $file['size'] > $config['max_filesize'] * 1024 * 1024) {
                 return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.maxsize.error', $config['max_filesize']));
             }
         }
         return $this->format(self::API_SUCCESS, 'ok');
     } catch (Exception $e) {
         return $this->format(self::API_FAIL, $e->getMessage());
     }
 }
예제 #9
0
 /**
  * 测试执行入口
  */
 public function runTest()
 {
     if (!\HuiLib\App\Request\RequestBase::isCli() && (APP_ENV == \HuiLib\Bootstrap::ENV_PRODUCTION || APP_ENV == \HuiLib\Bootstrap::ENV_STAGING)) {
         exit('not support.');
     }
     //bin运行
     if (RUN_METHOD == \HuiLib\Bootstrap::RUN_BIN) {
         if (!empty($_SERVER['argv'][1])) {
             $class = trim($_SERVER['argv'][1]);
         } else {
             exit('empty bin param.');
         }
         echo 'RUN_EVN:' . APP_ENV . PHP_EOL;
     } else {
         //web运行
         $queryString = \HuiLib\Helper\Param::getQueryString();
         parse_str($queryString, $info);
         if (empty($info)) {
             exit('empty web param.');
         }
         //获取类名
         $class = key($info);
     }
     //初始化测试库
     $instance = $class::getInstance();
     //执行
     $instance->run();
 }