mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进Request类
This commit is contained in:
@@ -415,7 +415,7 @@ class Request
|
|||||||
foreach (Config::get('pathinfo_fetch') as $type) {
|
foreach (Config::get('pathinfo_fetch') as $type) {
|
||||||
if (!empty($_SERVER[$type])) {
|
if (!empty($_SERVER[$type])) {
|
||||||
$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?
|
$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?
|
||||||
substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
|
substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -522,8 +522,11 @@ class Request
|
|||||||
return $this->server('REQUEST_METHOD') ?: 'GET';
|
return $this->server('REQUEST_METHOD') ?: 'GET';
|
||||||
} elseif (!$this->method) {
|
} elseif (!$this->method) {
|
||||||
if (isset($_POST[Config::get('var_method')])) {
|
if (isset($_POST[Config::get('var_method')])) {
|
||||||
$this->method = strtoupper($_POST[Config::get('var_method')]);
|
$method = strtoupper($_POST[Config::get('var_method')]);
|
||||||
$this->{$this->method}($_POST);
|
if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
|
||||||
|
$this->method = $method;
|
||||||
|
$this->{$this->method}($_POST);
|
||||||
|
}
|
||||||
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
|
||||||
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
|
||||||
} else {
|
} else {
|
||||||
@@ -672,8 +675,8 @@ class Request
|
|||||||
public function route($name = '', $default = null, $filter = '')
|
public function route($name = '', $default = null, $filter = '')
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
$this->mergeParam = false;
|
$this->mergeParam = false;
|
||||||
return $this->route = array_merge($this->route, $name);
|
return $this->route = array_merge($this->route, $name);
|
||||||
}
|
}
|
||||||
return $this->input($this->route, $name, $default, $filter);
|
return $this->input($this->route, $name, $default, $filter);
|
||||||
@@ -719,8 +722,8 @@ class Request
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
$this->mergeParam = false;
|
$this->mergeParam = false;
|
||||||
return $this->post = array_merge($this->post, $name);
|
return $this->post = array_merge($this->post, $name);
|
||||||
}
|
}
|
||||||
return $this->input($this->post, $name, $default, $filter);
|
return $this->input($this->post, $name, $default, $filter);
|
||||||
@@ -792,8 +795,8 @@ class Request
|
|||||||
$this->request = $_REQUEST;
|
$this->request = $_REQUEST;
|
||||||
}
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
$this->mergeParam = false;
|
$this->mergeParam = false;
|
||||||
return $this->request = array_merge($this->request, $name);
|
return $this->request = array_merge($this->request, $name);
|
||||||
}
|
}
|
||||||
return $this->input($this->request, $name, $default, $filter);
|
return $this->input($this->request, $name, $default, $filter);
|
||||||
@@ -1294,7 +1297,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function ip($type = 0, $adv = true)
|
public function ip($type = 0, $adv = true)
|
||||||
{
|
{
|
||||||
$type = $type ? 1 : 0;
|
$type = $type ? 1 : 0;
|
||||||
static $ip = null;
|
static $ip = null;
|
||||||
if (null !== $ip) {
|
if (null !== $ip) {
|
||||||
return $ip[$type];
|
return $ip[$type];
|
||||||
@@ -1633,7 +1636,7 @@ class Request
|
|||||||
throw new \think\exception\HttpResponseException($response);
|
throw new \think\exception\HttpResponseException($response);
|
||||||
} elseif (Cache::has($key)) {
|
} elseif (Cache::has($key)) {
|
||||||
list($content, $header) = Cache::get($key);
|
list($content, $header) = Cache::get($key);
|
||||||
$response = Response::create($content)->header($header);
|
$response = Response::create($content)->header($header);
|
||||||
throw new \think\exception\HttpResponseException($response);
|
throw new \think\exception\HttpResponseException($response);
|
||||||
} else {
|
} else {
|
||||||
$this->cache = [$key, $expire, $tag];
|
$this->cache = [$key, $expire, $tag];
|
||||||
|
|||||||
Reference in New Issue
Block a user