tp框架网络请求
- 1 网络请求
- 2 请求信息
- 2-1 Url相关
- Request->url()
- Request->baseUrl()
- Request->scheme()
- Request->domain()
- Request->host()
- Request->port()
- Request->query()
- Request->ext()
- Request->root()
- Request->pathinfo
- 2-2 请求相关
- Request->baseFile()
- Request->time()
- Request->type()
- Request->method()
- Request->protocol()
- Request->remotePort()
- 2-3 请求信息监测
- Request->isGet()
- Request->isPost()
- Request->isPut()
- Request->isDelete()
- Request->isHead()
- Request->isPatch()
- Request->isOptions()
- Request->isCli()
- Request->isCgi()
- Request->issSsl()
- Request->isAjax()
- Request->isPjax()
- Request->isMobile()
- 2-4 请求数据过滤
- Request->filter()
- Request->filterValue()
- Request->filterExp()
- Request->typeCast()
- 2-5 设置与获取同一函数
- Request->input()
- Request->param()
- Request->get()
- Request->post()
- Request->put()
- Request->delete()
- Request->patch()
- Reques->request()
- Request->has()
- Request->only()
- Request->except()
- Request->route()
- Request->routeInfo()
- Request->session()
- Request->cookie()
- Request->server()
- Request->getContent()
- Request->file()
- Request->env()
- Request->header()
- Request->langset()
- Request->dispatch()
- Request->module()
- Request->controller()
- Request->action()
- 2-1 Url相关
- 3 请求创建与设置
- 3-1 网络请求创建
- Request::instance()
- Request->__construct()
- Request::create()
- 3-2 网络请求设置
- 3-1 网络请求创建
1 网络请求
网络请求
对客户端而言,指服务器发起的请求操作。
对服务器端而言,指客户端发起的请求信息。
服务器端主要用来对客户端发起的网络请求进行处理。
2 请求信息
2-1 Url相关
Request->url()
获取当前完整的url(包含QUERY_STRING)
public function url($url = null){if (!is_null($url) && true !== $url) {$this->url = $url;return $this;} elseif (!$this->url) {if (IS_CLI) {$this->url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {$this->url = $_SERVER['HTTP_X_REWRITE_URL'];} elseif (isset($_SERVER['REQUEST_URI'])) {$this->url = $_SERVER['REQUEST_URI'];} elseif (isset($_SERVER['ORIG_PATH_INFO'])) {$this->url = $_SERVER['ORIG_PATH_INFO'] . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');} else {$this->url = '';}}return true === $url ? $this->domain() . $this->url : $this->url;}
Request->baseUrl()
获取当前URL,(不包含QUERY_STRING)
public function baseUrl($url = null){if (!is_null($url) && true !== $url) {$this->baseUrl = $url;return $this;} elseif (!$this->baseUrl) {$str = $this->url();$this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str;}return true === $url ? $this->domain() . $this->baseUrl : $this->baseUrl;}
Request->scheme()
获取URL中的scheme参数(http或者https)
public function scheme(){return $this->isSsl() ? 'https' : 'http';}
Request->domain()
获取URL的域名信息(如http://baidu.com)
public function domain($domain = null){if (!is_null($domain)) {$this->domain = $domain;return $this;} elseif (!$this->domain) {$this->domain = $this->scheme() . '://' . $this->host();}return $this->domain;}
Request->host()
获取URL的host参数
public function host(){return $this->server('HTTP_HOST');}
Request->port()
获取URL的port参数
public function port(){return $this->server('SERVER_PORT');}
Request->query()
获取URL的query参数
public function query(){return $this->server('QUERY_STRING');}
Request->ext()
获取URL的访问后缀(.html或.php)
public function ext(){return pathinfo($this->pathinfo(), PATHINFO_EXTENSION);}
Request->root()
获取URL访问的根地址
public function root($url = null){if (!is_null($url) && true !== $url) {$this->root = $url;return $this;} elseif (!$this->root) {$file = $this->baseFile();if ($file && 0 !== strpos($this->url(), $file)) {$file = str_replace('\\', '/', dirname($file));}$this->root = rtrim($file, '/');}return true === $url ? $this->domain() . $this->root : $this->root;}
Request->pathinfo
获取当前URL的pathinfo信息(包含URL后缀)
public function pathinfo(){if (is_null($this->pathinfo)) {if (isset($_GET[Config::get('var_pathinfo')])) {// 判断URL里面是否有兼容模式参数$_SERVER['PATH_INFO'] = $_GET[Config::get('var_pathinfo')];unset($_GET[Config::get('var_pathinfo')]);} elseif (IS_CLI) {// CLI模式下 index.php module/controller/action/params/...$_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';}// 分析PATHINFO信息if (!isset($_SERVER['PATH_INFO'])) {foreach (Config::get('pathinfo_fetch') as $type) {if (!empty($_SERVER[$type])) {$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];break;}}}$this->pathinfo = empty($_SERVER['PATH_INFO']) ? '/' : ltrim($_SERVER['PATH_INFO'], '/');}return $this->pathinfo;}
2-2 请求相关
Request->baseFile()
获取当前请求的执行文件
public function baseFile($file = null){if (!is_null($file) && true !== $file) {$this->baseFile = $file;return $this;} elseif (!$this->baseFile) {$url = '';if (!IS_CLI) {$script_name = basename($_SERVER['SCRIPT_FILENAME']);if (basename($_SERVER['SCRIPT_NAME']) === $script_name) {$url = $_SERVER['SCRIPT_NAME'];} elseif (basename($_SERVER['PHP_SELF']) === $script_name) {$url = $_SERVER['PHP_SELF'];} elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $script_name) {$url = $_SERVER['ORIG_SCRIPT_NAME'];} elseif (($pos = strpos($_SERVER['PHP_SELF'], '/' . $script_name)) !== false) {$url = substr($_SERVER['SCRIPT_NAME'], 0, $pos) . '/' . $script_name;} elseif (isset($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']) === 0) {$url = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']));}}$this->baseFile = $url;}return true === $file ? $this->domain() . $this->baseFile : $this->baseFile;}
Request->time()
获取当前请求时间
public function time($float = false){return $float ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME'];}
Request->type()
获取当前请求的资源类型
public function type(){$accept = isset($this->server['HTTP_ACCEPT']) ? $this->server['HTTP_ACCEPT'] : $_SERVER['HTTP_ACCEPT'];if (empty($accept)) {return false;}foreach ($this->mimeType as $key => $val) {$array = explode(',', $val);foreach ($array as $k => $v) {if (stristr($accept, $v)) {return $key;}}}return false;}
Request->method()
获取当前的请求类型(GET/POST/CLI)
public function method($method = false){if (true === $method) {// 获取原始请求类型return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);} elseif (!$this->method) {if (isset($_POST[Config::get('var_method')])) {$this->method = strtoupper($_POST[Config::get('var_method')]);$this->{$this->method}($_POST);} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);} else {$this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);}}return $this->method;}
Request->protocol()
获取当前请求的通信协议
public function protocol(){return $this->server('SERVER_PROTOCOL');}
Request->remotePort()
获取当前请求的远程端口
public function remotePort(){return $this->server('REMOTE_PORT');}
2-3 请求信息监测
Request->isGet()
检查当前是否Get请求
public function isGet(){return $this->method() == 'GET';}
Request->isPost()
检查当前是否Post请求
public function isPost(){return $this->method() == 'POST';}
Request->isPut()
检查是否为Put请求
public function isPut(){return $this->method() == 'PUT';}
Request->isDelete()
检查是否为Delete请求
public function isDelete(){return $this->method() == 'DELETE';}
Request->isHead()
检查是否为Head请求
public function isHead(){return $this->method() == 'HEAD';}
Request->isPatch()
检查是否为Patch请求
public function isPatch(){return $this->method() == 'PATCH';}
Request->isOptions()
检查是否为options请求
public function isOptions(){return $this->method() == 'OPTIONS';}
Request->isCli()
检查是否为Cli请求
public function isCli(){return PHP_SAPI == 'cli';}
Request->isCgi()
检查是否为Cgi请求
public function isCgi(){return strpos(PHP_SAPI, 'cgi') === 0;}
Request->issSsl()
检查是否为ssl请求
public function isSsl(){$server = array_merge($_SERVER, $this->server);if (isset($server['HTTPS']) && ('1' == $server['HTTPS'] || 'on' == strtolower($server['HTTPS']))) {return true;} elseif (isset($server['REQUEST_SCHEME']) && 'https' == $server['REQUEST_SCHEME']) {return true;} elseif (isset($server['SERVER_PORT']) && ('443' == $server['SERVER_PORT'])) {return true;} elseif (isset($server['HTTP_X_FORWARDED_PROTO']) && 'https' == $server['HTTP_X_FORWARDED_PROTO']) {return true;}return false;}
Request->isAjax()
检查是否为Ajax请求
public function isAjax(){$value = $this->server('HTTP_X_REQUESTED_WITH');return (!is_null($value) && strtolower($value) == 'xmlhttprequest') ? true : false;}
Request->isPjax()
检查是否为Pjax请求
public function isPjax(){return !is_null($this->server('HTTP_X_PJAX')) ? true : false;}
Request->isMobile()
检查是否手机访问
public function isMobile(){if (isset($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], "wap")) {return true;} elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML")) {return true;} elseif (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {return true;} elseif (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])) {return true;} else {return false;}}
2-4 请求数据过滤
Request->filter()
获取或设置过滤规则
public function filter($filter = null){if (is_null($filter)) {return $this->filter;} else {$this->filter = $filter;}}
Request->filterValue()
递归过滤给的的值
private function filterValue(&$value, $key, $filters){$default = array_pop($filters);foreach ($filters as $filter) {if (is_callable($filter)) {// 调用函数或者方法过滤$value = call_user_func($filter, $value);} elseif (is_scalar($value)) {if (strpos($filter, '/')) {// 正则过滤if (!preg_match($filter, $value)) {// 匹配不成功返回默认值$value = $default;break;}} elseif (!empty($filter)) {// filter函数不存在时, 则使用filter_var进行过滤// filter为非整形值时, 调用filter_id取得过滤id$value = filter_var($value, is_int($filter) ? $filter : filter_id($filter));if (false === $value) {$value = $default;break;}}}}return $this->filterExp($value);}
Request->filterExp()
过滤表单中的表达式
public function filterExp(&$value){// 过滤查询特殊字符if (is_string($value) && preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) {$value .= ' ';}// TODO 其他安全过滤}
Request->typeCast()
强制请求数据的类型转换
private function typeCast(&$data, $type){switch (strtolower($type)) {// 数组case 'a':$data = (array) $data;break;// 数字case 'd':$data = (int) $data;break;// 浮点case 'f':$data = (float) $data;break;// 布尔case 'b':$data = (boolean) $data;break;// 字符串case 's':default:if (is_scalar($data)) {$data = (string) $data;} else {throw new \InvalidArgumentException('variable type error:' . gettype($data));}}}
2-5 设置与获取同一函数
Request->input()
input()是设置和获取输入信息的核心实现函数
如果传入的name参数为false,则获取对应数据源
如果传入的name参数非false,则设置name为对应数据源
input()在下面的多个函数中会被调用
public function input($data = [], $name = '', $default = null, $filter = null){if (false === $name) {// 获取原始数据return $data;}$name = (string) $name;if ('' != $name) {// 解析nameif (strpos($name, '/')) {list($name, $type) = explode('/', $name);} else {$type = 's';}// 按.拆分成多维数组进行判断foreach (explode('.', $name) as $val) {if (isset($data[$val])) {$data = $data[$val];} else {// 无输入数据,返回默认值return $default;}}if (is_object($data)) {return $data;}}// 解析过滤器$filter = $filter ?: $this->filter;if (is_string($filter)) {$filter = explode(',', $filter);} else {$filter = (array) $filter;}$filter[] = $default;if (is_array($data)) {array_walk_recursive($data, [$this, 'filterValue'], $filter);reset($data);} else {$this->filterValue($data, $name, $filter);}if (isset($type) && $data !== $default) {// 强制类型转换$this->typeCast($data, $type);}return $data;}
Request->param()
public function param($name = '', $default = null, $filter = null){if (empty($this->param)) {$method = $this->method(true);// 自动获取请求变量switch ($method) {case 'POST':$vars = $this->post(false);break;case 'PUT':case 'DELETE':case 'PATCH':$vars = $this->put(false);break;default:$vars = [];}// 当前请求参数和URL地址中的参数合并$this->param = array_merge($this->get(false), $vars, $this->route(false));}if (true === $name) {// 获取包含文件上传信息的数组$file = $this->file();$data = array_merge($this->param, $file);return $this->input($data, '', $default, $filter);}return $this->input($this->param, $name, $default, $filter);}
Request->get()
public function get($name = '', $default = null, $filter = null){if (empty($this->get)) {$this->get = $_GET;}if (is_array($name)) {$this->param = [];return $this->get = array_merge($this->get, $name);}return $this->input($this->get, $name, $default, $filter);}
Request->post()
public function post($name = '', $default = null, $filter = null){if (empty($this->post)) {$this->post = $_POST;}if (is_array($name)) {$this->param = [];return $this->post = array_merge($this->post, $name);}return $this->input($this->post, $name, $default, $filter);}
Request->put()
public function put($name = '', $default = null, $filter = null){if (is_null($this->put)) {$content = file_get_contents('php://input');if (strpos($content, '":')) {$this->put = json_decode($content, true);} else {parse_str($content, $this->put);}}if (is_array($name)) {$this->param = [];return $this->put = is_null($this->put) ? $name : array_merge($this->put, $name);}return $this->input($this->put, $name, $default, $filter);}
Request->delete()
public function delete($name = '', $default = null, $filter = null){return $this->put($name, $default, $filter);}
Request->patch()
public function patch($name = '', $default = null, $filter = null){return $this->put($name, $default, $filter);}
Reques->request()
public function request($name = '', $default = null, $filter = null){if (empty($this->request)) {$this->request = $_REQUEST;}if (is_array($name)) {$this->param = [];return $this->request = array_merge($this->request, $name);}return $this->input($this->request, $name, $default, $filter);}
Request->has()
检查是否存在name参数
public function has($name, $type = 'param', $checkEmpty = false){if (empty($this->$type)) {$param = $this->$type();} else {$param = $this->$type;}// 按.拆分成多维数组进行判断foreach (explode('.', $name) as $val) {if (isset($param[$val])) {$param = $param[$val];} else {return false;}}return ($checkEmpty && '' === $param) ? false : true;}
Request->only()
只获取name的参数信息
public function only($name, $type = 'param'){$param = $this->$type();if (is_string($name)) {$name = explode(',', $name);}$item = [];foreach ($name as $key) {if (isset($param[$key])) {$item[$key] = $param[$key];}}return $item;}
Request->except()
排除name参数,获取其他所有参数信息
public function except($name, $type = 'param'){$param = $this->$type();if (is_string($name)) {$name = explode(',', $name);}foreach ($name as $key) {if (isset($param[$key])) {unset($param[$key]);}}return $param;}
Request->route()
获取设置路由参数
public function route($name = '', $default = null, $filter = null){if (is_array($name)) {$this->param = [];return $this->route = array_merge($this->route, $name);}return $this->input($this->route, $name, $default, $filter);}
Request->routeInfo()
获取当前请求的路由信息
public function routeInfo($route = []){if (!empty($route)) {$this->routeInfo = $route;} else {return $this->routeInfo;}}
Request->session()
获取和设置session信息
public function session($name = '', $default = null, $filter = null){if (empty($this->session)) {$this->session = Session::get();}if (is_array($name)) {return $this->session = array_merge($this->session, $name);}return $this->input($this->session, $name, $default, $filter);}
Request->cookie()
获取和设置cookie信息
public function cookie($name = '', $default = null, $filter = null){if (empty($this->cookie)) {$this->cookie = $_COOKIE;}if (is_array($name)) {return $this->cookie = array_merge($this->cookie, $name);}return $this->input($this->cookie, $name, $default, $filter);}
Request->server()
设置和获取server参数信息
public function server($name = '', $default = null, $filter = null){if (empty($this->server)) {$this->server = $_SERVER;}if (is_array($name)) {return $this->server = array_merge($this->server, $name);}return $this->input($this->server, false === $name ? false : strtoupper($name), $default, $filter);}
Request->getContent()
获取或设置当前的请求内容content
public function getContent(){if (is_null($this->content)) {$this->content = file_get_contents('php://input');}return $this->content;}
Request->file()
获取上传的文件信息
public function file($name = ''){if (empty($this->file)) {$this->file = isset($_FILES) ? $_FILES : [];}if (is_array($name)) {return $this->file = array_merge($this->file, $name);}$files = $this->file;if (!empty($files)) {// 处理上传文件$array = [];foreach ($files as $key => $file) {if (is_array($file['name'])) {$item = [];$keys = array_keys($file);$count = count($file['name']);for ($i = 0; $i < $count; $i++) {if (empty($file['tmp_name'][$i])) {continue;}$temp['key'] = $key;foreach ($keys as $_key) {$temp[$_key] = $file[$_key][$i];}$item[] = (new File($temp['tmp_name']))->setUploadInfo($temp);}$array[$key] = $item;} else {if ($file instanceof File) {$array[$key] = $file;} else {if (empty($file['tmp_name'])) {continue;}$array[$key] = (new File($file['tmp_name']))->setUploadInfo($file);}}}if (strpos($name, '.')) {list($name, $sub) = explode('.', $name);}if ('' === $name) {// 获取全部文件return $array;} elseif (isset($sub) && isset($array[$name][$sub])) {return $array[$name][$sub];} elseif (isset($array[$name])) {return $array[$name];}}return null;}
Request->env()
获取或设置当前请求的环境变量信息
public function env($name = '', $default = null, $filter = null){if (empty($this->env)) {$this->env = $_ENV;}if (is_array($name)) {return $this->env = array_merge($this->env, $name);}return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter);}
Request->header()
获取或设置当前请求的header
public function header($name = '', $default = null){if (empty($this->header)) {$header = [];$server = $this->server ?: $_SERVER;foreach ($server as $key => $val) {if (0 === strpos($key, 'HTTP_')) {$key = str_replace('_', '-', strtolower(substr($key, 5)));$header[$key] = $val;}}if (isset($server['CONTENT_TYPE'])) {$header['content-type'] = $server['CONTENT_TYPE'];}if (isset($server['CONTENT_LENGTH'])) {$header['content-length'] = $server['CONTENT_LENGTH'];}$this->header = array_change_key_case($header);}if (is_array($name)) {return $this->header = array_merge($this->header, $name);}if ('' === $name) {return $this->header;}$name = str_replace('_', '-', strtolower($name));return isset($this->header[$name]) ? $this->header[$name] : $default;}
Request->langset()
获取或设置当前的语言设置
public function langset($lang = null){if (!is_null($lang)) {$this->langset = $lang;return $this;} else {return $this->langset ?: '';}}
Request->dispatch()
获取或设置当前请求调度信息
public function dispatch($dispatch = null){if (!is_null($dispatch)) {$this->dispatch = $dispatch;}return $this->dispatch;}
Request->module()
获取或设置请求当前模块名
public function module($module = null){if (!is_null($module)) {$this->module = $module;return $this;} else {return $this->module ?: '';}}
Request->controller()
获取或设置当前请求控制器
public function controller($controller = null){if (!is_null($controller)) {$this->controller = $controller;return $this;} else {return $this->controller ?: '';}}
Request->action()
获取或设置当前请求操作
public function action($action = null){if (!is_null($action)) {$this->action = $action;return $this;} else {return $this->action ?: '';}}
3 请求创建与设置
3-1 网络请求创建
Request::instance()
单例模式创建全局唯一请求对象
public static function instance($options = []){if (is_null(self::$instance)) {self::$instance = new static($options);}return self::$instance;}
Request->__construct()
网络请求构造函数
public function __construct($options = []){foreach ($options as $name => $item) {if (property_exists($this, $name)) {$this->$name = $item;}}if (is_null($this->filter)) {$this->filter = Config::get('default_filter');}}
Request::create()
网络请求 自定义创建
public static function create($uri, $method = 'GET', $params = [], $cookie = [], $files = [], $server = [], $content = null){$server['PATH_INFO'] = '';$server['REQUEST_METHOD'] = strtoupper($method);$info = parse_url($uri);if (isset($info['host'])) {$server['SERVER_NAME'] = $info['host'];$server['HTTP_HOST'] = $info['host'];}if (isset($info['scheme'])) {if ('https' === $info['scheme']) {$server['HTTPS'] = 'on';$server['SERVER_PORT'] = 443;} else {unset($server['HTTPS']);$server['SERVER_PORT'] = 80;}}if (isset($info['port'])) {$server['SERVER_PORT'] = $info['port'];$server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $info['port'];}if (isset($info['user'])) {$server['PHP_AUTH_USER'] = $info['user'];}if (isset($info['pass'])) {$server['PHP_AUTH_PW'] = $info['pass'];}if (!isset($info['path'])) {$info['path'] = '/';}$options = [];$queryString = '';if (isset($info['query'])) {parse_str(html_entity_decode($info['query']), $query);if (!empty($params)) {$params = array_replace($query, $params);$queryString = http_build_query($query, '', '&');} else {$params = $query;$queryString = $info['query'];}} elseif (!empty($params)) {$queryString = http_build_query($params, '', '&');}$server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : '');$server['QUERY_STRING'] = $queryString;$options['cookie'] = $cookie;$options['param'] = $params;$options['file'] = $files;$options['server'] = $server;$options['url'] = $server['REQUEST_URI'];$options['baseUrl'] = $info['path'];$options['pathinfo'] = '/' == $info['path'] ? '/' : ltrim($info['path'], '/');$options['method'] = $server['REQUEST_METHOD'];$options['domain'] = $info['scheme'] . '://' . $server['HTTP_HOST'];$options['content'] = $content;self::$instance = new self($options);return self::$instance;}
附tp8框架的最新请求
/*** @see \think\Request* @package think\facade* @mixin \think\Request* @method static \think\Request setDomain(string $domain) 设置当前包含协议的域名* @method static string domain(bool $port = false) 获取当前包含协议的域名* @method static string rootDomain() 获取当前根域名* @method static \think\Request setSubDomain(string $domain) 设置当前泛域名的值* @method static string subDomain() 获取当前子域名* @method static \think\Request setPanDomain(string $domain) 设置当前泛域名的值* @method static string panDomain() 获取当前泛域名的值* @method static \think\Request setUrl(string $url) 设置当前完整URL 包括QUERY_STRING* @method static string url(bool $complete = false) 获取当前完整URL 包括QUERY_STRING* @method static \think\Request setBaseUrl(string $url) 设置当前URL 不含QUERY_STRING* @method static string baseUrl(bool $complete = false) 获取当前URL 不含QUERY_STRING* @method static string baseFile(bool $complete = false) 获取当前执行的文件 SCRIPT_NAME* @method static \think\Request setRoot(string $url) 设置URL访问根地址* @method static string root(bool $complete = false) 获取URL访问根地址* @method static string rootUrl() 获取URL访问根目录* @method static \think\Request setPathinfo(string $pathinfo) 设置当前请求的pathinfo* @method static string pathinfo() 获取当前请求URL的pathinfo信息(含URL后缀)* @method static string ext() 当前URL的访问后缀* @method static integer|float time(bool $float = false) 获取当前请求的时间* @method static string type() 当前请求的资源类型* @method static void mimeType(string|array $type, string $val = '') 设置资源类型* @method static \think\Request setMethod(string $method) 设置请求类型* @method static string method(bool $origin = false) 当前的请求类型* @method static bool isGet() 是否为GET请求* @method static bool isPost() 是否为POST请求* @method static bool isPut() 是否为PUT请求* @method static bool isDelete() 是否为DELTE请求* @method static bool isHead() 是否为HEAD请求* @method static bool isPatch() 是否为PATCH请求* @method static bool isOptions() 是否为OPTIONS请求* @method static bool isCli() 是否为cli* @method static bool isCgi() 是否为cgi* @method static mixed param(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取当前请求的参数* @method static \think\Request setRule(Rule $rule) 设置路由变量* @method static Rule|null rule() 获取当前路由对象* @method static \think\Request setRoute(array $route) 设置路由变量* @method static mixed route(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取路由参数* @method static mixed get(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取GET参数* @method static mixed middleware(mixed $name, mixed $default = null) 获取中间件传递的参数* @method static mixed post(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取POST参数* @method static mixed put(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取PUT参数* @method static mixed delete(mixed $name = '', mixed $default = null, string|array|null $filter = '') 设置获取DELETE参数* @method static mixed patch(mixed $name = '', mixed $default = null, string|array|null $filter = '') 设置获取PATCH参数* @method static mixed request(string|array $name = '', mixed $default = null, string|array|null $filter = '') 获取request变量* @method static mixed env(string $name = '', string $default = null) 获取环境变量* @method static mixed session(string $name = '', string $default = null) 获取session数据* @method static mixed cookie(mixed $name = '', string $default = null, string|array|null $filter = '') 获取cookie参数* @method static mixed server(string $name = '', string $default = '') 获取server参数* @method static null|array|UploadedFile file(string $name = '') 获取上传的文件信息* @method static string|array header(string $name = '', string $default = null) 设置或者获取当前的Header* @method static mixed input(array $data = [], string|false $name = '', mixed $default = null, string|array|null $filter = '') 获取变量 支持过滤和默认值* @method static mixed filter(mixed $filter = null) 设置或获取当前的过滤规则* @method static mixed filterValue(mixed &$value, mixed $key, array $filters) 递归过滤给定的值* @method static bool has(string $name, string $type = 'param', bool $checkEmpty = false) 是否存在某个请求参数* @method static array only(array $name, mixed $data = 'param', string|array|null $filter = '') 获取指定的参数* @method static mixed except(array $name, string $type = 'param') 排除指定参数获取* @method static bool isSsl() 当前是否ssl* @method static bool isJson() 当前是否JSON请求* @method static bool isAjax(bool $ajax = false) 当前是否Ajax请求* @method static bool isPjax(bool $pjax = false) 当前是否Pjax请求* @method static string ip() 获取客户端IP地址* @method static boolean isValidIP(string $ip, string $type = '') 检测是否是合法的IP地址* @method static string ip2bin(string $ip) 将IP地址转换为二进制字符串* @method static bool isMobile() 检测是否使用手机访问* @method static string scheme() 当前URL地址中的scheme参数* @method static string query() 当前请求URL地址中的query参数* @method static \think\Request setHost(string $host) 设置当前请求的host(包含端口)* @method static string host(bool $strict = false) 当前请求的host* @method static int port() 当前请求URL地址中的port参数* @method static string protocol() 当前请求 SERVER_PROTOCOL* @method static int remotePort() 当前请求 REMOTE_PORT* @method static string contentType() 当前请求 HTTP_CONTENT_TYPE* @method static string secureKey() 获取当前请求的安全Key* @method static \think\Request setController(string $controller) 设置当前的控制器名* @method static \think\Request setAction(string $action) 设置当前的操作名* @method static string controller(bool $convert = false) 获取当前的控制器名* @method static string action(bool $convert = false) 获取当前的操作名* @method static string getContent() 设置或者获取当前请求的content* @method static string getInput() 获取当前请求的php://input* @method static string buildToken(string $name = '__token__', mixed $type = 'md5') 生成请求令牌* @method static bool checkToken(string $token = '__token__', array $data = []) 检查请求令牌* @method static \think\Request withMiddleware(array $middleware) 设置在中间件传递的数据* @method static \think\Request withGet(array $get) 设置GET数据* @method static \think\Request withPost(array $post) 设置POST数据* @method static \think\Request withCookie(array $cookie) 设置COOKIE数据* @method static \think\Request withSession(Session $session) 设置SESSION数据* @method static \think\Request withServer(array $server) 设置SERVER数据* @method static \think\Request withHeader(array $header) 设置HEADER数据* @method static \think\Request withEnv(Env $env) 设置ENV数据* @method static \think\Request withInput(string $input) 设置php://input数据* @method static \think\Request withFiles(array $files) 设置文件上传数据* @method static \think\Request withRoute(array $route) 设置ROUTE变量* @method static mixed __set(string $name, mixed $value) 设置中间传递数据* @method static mixed __get(string $name) 获取中间传递数据的值* @method static boolean __isset(string $name) 检测中间传递数据的值* @method static bool offsetExists(mixed $name)* @method static mixed offsetGet(mixed $name)* @method static mixed offsetSet(mixed $name, $value)* @method static mixed offsetUnset(mixed $name)*/