Example #1
0
 public function main()
 {
     $project = Config::getField('project', 'name', 'zphp');
     $data = $project . " runing!\n";
     $params = Request::getParams();
     if (!empty($params)) {
         foreach ($params as $key => $val) {
             $data .= "key:{$key}=>{$val}\n";
         }
     }
     return ['data' => ['data' => ['zphp' => $data]]];
 }
Example #2
0
 public function display()
 {
     if (Request::isHttp()) {
         $params = Request::getParams();
         if (isset($params['jsoncallback'])) {
             Response::header("Content-Type", 'application/x-javascript; charset=utf-8');
         } else {
             Response::header("Content-Type", "application/json; charset=utf-8");
         }
     }
     $data = \json_encode($this->model);
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #3
0
 public static function end($key = 'ALL', $logName = 'debug')
 {
     $endTime = self::getMicroTime();
     $run_id = 0;
     if (self::$xhprof) {
         $xhprof_data = \xhprof_disable();
         $xhprof_runs = new \XHProfRuns_Default();
         $run_id = $xhprof_runs->save_run($xhprof_data, 'random');
     }
     $times = $endTime - self::$records[$key]['start_time'];
     $mem_use = memory_get_usage() - self::$records[$key]['memory_use'];
     unset(self::$records[$key]);
     if (empty($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = '';
     }
     Log::info($logName, array($times, self::convert($mem_use), $run_id, $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], Request::getParams()));
 }
Example #4
0
 public function display()
 {
     $data = \json_encode($this->model, JSON_UNESCAPED_UNICODE);
     if (Request::isHttp()) {
         $params = Request::getParams();
         $key = Config::getField('project', 'jsonp', 'jsoncallback');
         if (isset($params[$key])) {
             Response::header("Content-Type", 'application/x-javascript; charset=utf-8');
             $data = $params[$key] . '(' . $data . ')';
         } else {
             Response::header("Content-Type", "application/json; charset=utf-8");
         }
     }
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #5
0
 /**
  * @param $key
  * @param null $default
  * @param array|null $params
  * @param bool|true $notEmpty
  * @return mixed|null|string
  * @throws common\MyException
  * @desc 获取json类型参数,转换为数组
  */
 protected function getJson($key, $default = null, array $params = null, $notEmpty = true)
 {
     if (empty($params)) {
         $params = Request::getParams();
     }
     if (empty($params[$key])) {
         if (isset($params[$key])) {
             return \trim($params[$key]);
         }
         if (null !== $default) {
             return $default;
         }
         throw new common\MyException("no params {$key}", common\ERROR::PARAM_ERROR);
     }
     $data = \json_decode($params[$key], true);
     if (!empty($notEmpty) && empty($data)) {
         throw new common\MyException('params no empty', common\ERROR::PARAM_ERROR);
     }
     return $data;
 }
Example #6
0
 public function _before()
 {
     $this->params = Request::getParams();
     return true;
 }