123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * Created by PhpStorm.
- * User: JZ
- * Date: 2019/7/18
- * Time: 17:23
- */
- class HttpParameter {
- private $params; // 参数
- private $listFiles; // 文件列表
- private $httpMethod; // 请求方式
- private $jsonParams; // json参数
- /**
- * HttpParameter constructor.
- * @param $httpMethod
- */
- public function __construct($httpMethod) {
- $this->httpMethod = $httpMethod;
- }
- /**
- * post请求
- * @return HttpParameter
- */
- public static function httpPostParamer(){
- return new HttpParameter(HttpMethod::POST);
- }
- /**
- * get请求
- * @return HttpParameter
- */
- public static function httpGetParamer(){
- return new HttpParameter(HttpMethod::GET);
- }
- /**
- * 获取url参数(一般用于get请求)
- * @return null|string
- */
- public function getQueryString(){
- $urlParams = $this->getParams();
- if(is_null($urlParams)){
- return null;
- }
- $string = [];
- if($urlParams && is_array($urlParams)){
- foreach ($urlParams as $key=> $value){
- $string[] = $key.'='.$value;
- }
- }
- return implode('&',$string);
- }
- /**
- * @return mixed
- */
- public function getParams()
- {
- return $this->params;
- }
- /**
- * @param mixed $params
- */
- public function setParams($params)
- {
- $this->params = $params;
- }
- public function addParam($name, $value) {
- $params = $this->params;
- if (is_null($params)) {
- $params = array();
- }
- if(is_array($params)){
- $params[$name] = $value;
- }
- $this->params = $params;
- }
- /**
- * @return mixed
- */
- public function getHttpMethod()
- {
- return $this->httpMethod;
- }
- /**
- * @param mixed $httpMethod
- */
- public function setHttpMethod($httpMethod)
- {
- $this->httpMethod = $httpMethod;
- }
- /**
- * @return mixed
- */
- public function getJsonParams()
- {
- return $this->jsonParams;
- }
- /**
- * @param mixed $jsonParams
- */
- public function setJsonParams($jsonParams)
- {
- $this->jsonParams = $jsonParams;
- }
- /**
- * 是否是json请求
- */
- public function isJson() {
- if(is_null($this->jsonParams)){
- return false;
- }
- return true;
- }
- /**
- * @return mixed
- */
- public function getListFiles()
- {
- return $this->listFiles;
- }
- public function addListFiles($name, $files) {
- $listFiles = $this->listFiles;
- if (is_null($listFiles)) {
- $listFiles = array();
- }
- if(is_array($listFiles)){
- $listFiles[$name] = $files;
- }
- $this->listFiles = $listFiles;
- }
- /**
- * 请求是否包含多文件
- */
- public function isFiles(){
- if(is_null($this->listFiles)){
- return false;
- }
- return true;
- }
- }
|