mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进Request类 避免数据批量赋值的时候 影响原始数据获取
This commit is contained in:
@@ -655,11 +655,12 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function get($name = '', $default = null, $filter = null)
|
public function get($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->get)) {
|
||||||
|
$this->get = $_GET;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
return $this->get = array_merge($this->get, $name);
|
return $this->get = array_merge($this->get, $name);
|
||||||
} elseif (empty($this->get)) {
|
|
||||||
$this->get = $_GET;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->get, $name, $default, $filter);
|
return $this->input($this->get, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -674,11 +675,12 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function post($name = '', $default = null, $filter = null)
|
public function post($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->post)) {
|
||||||
|
$this->post = $_POST;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
return $this->post = array_merge($this->post, $name);
|
return $this->post = array_merge($this->post, $name);
|
||||||
} elseif (empty($this->post)) {
|
|
||||||
$this->post = $_POST;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->post, $name, $default, $filter);
|
return $this->input($this->post, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -693,10 +695,6 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function put($name = '', $default = null, $filter = null)
|
public function put($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
|
||||||
$this->param = [];
|
|
||||||
return $this->put = is_null($this->put) ? $name : array_merge($this->put, $name);
|
|
||||||
}
|
|
||||||
if (is_null($this->put)) {
|
if (is_null($this->put)) {
|
||||||
$content = file_get_contents('php://input');
|
$content = file_get_contents('php://input');
|
||||||
if (strpos($content, '":')) {
|
if (strpos($content, '":')) {
|
||||||
@@ -705,6 +703,11 @@ class Request
|
|||||||
parse_str($content, $this->put);
|
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);
|
return $this->input($this->put, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,11 +746,12 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function request($name = '', $default = null, $filter = null)
|
public function request($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->request)) {
|
||||||
|
$this->request = $_REQUEST;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
$this->param = [];
|
$this->param = [];
|
||||||
return $this->request = array_merge($this->request, $name);
|
return $this->request = array_merge($this->request, $name);
|
||||||
} elseif (empty($this->request)) {
|
|
||||||
$this->request = $_REQUEST;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->request ?: $_REQUEST, $name, $default, $filter);
|
return $this->input($this->request ?: $_REQUEST, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -762,10 +766,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function session($name = '', $default = null, $filter = null)
|
public function session($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->session)) {
|
||||||
|
$this->session = Session::get();
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->session = array_merge($this->session, $name);
|
return $this->session = array_merge($this->session, $name);
|
||||||
} elseif (empty($this->session)) {
|
|
||||||
$this->session = Session::get();
|
|
||||||
}
|
}
|
||||||
return $this->input($this->session, $name, $default, $filter);
|
return $this->input($this->session, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -780,10 +785,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function cookie($name = '', $default = null, $filter = null)
|
public function cookie($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->cookie)) {
|
||||||
|
$this->cookie = $_COOKIE;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->cookie = array_merge($this->cookie, $name);
|
return $this->cookie = array_merge($this->cookie, $name);
|
||||||
} elseif (empty($this->cookie)) {
|
|
||||||
$this->cookie = $_COOKIE;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->cookie, $name, $default, $filter);
|
return $this->input($this->cookie, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -798,10 +804,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function server($name = '', $default = null, $filter = null)
|
public function server($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->server)) {
|
||||||
|
$this->server = $_SERVER;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->server = array_merge($this->server, $name);
|
return $this->server = array_merge($this->server, $name);
|
||||||
} elseif (empty($this->server)) {
|
|
||||||
$this->server = $_SERVER;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->server, false === $name ? false : strtoupper($name), $default, $filter);
|
return $this->input($this->server, false === $name ? false : strtoupper($name), $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -814,10 +821,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function file($name = '')
|
public function file($name = '')
|
||||||
{
|
{
|
||||||
|
if (empty($this->file)) {
|
||||||
|
$this->file = isset($_FILES) ? $_FILES : [];
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->file = array_merge($this->file, $name);
|
return $this->file = array_merge($this->file, $name);
|
||||||
} elseif (empty($this->file)) {
|
|
||||||
$this->file = isset($_FILES) ? $_FILES : [];
|
|
||||||
}
|
}
|
||||||
$files = $this->file;
|
$files = $this->file;
|
||||||
if (!empty($files)) {
|
if (!empty($files)) {
|
||||||
@@ -874,10 +882,11 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function env($name = '', $default = null, $filter = null)
|
public function env($name = '', $default = null, $filter = null)
|
||||||
{
|
{
|
||||||
|
if (empty($this->env)) {
|
||||||
|
$this->env = $_ENV;
|
||||||
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->env = array_merge($this->env, $name);
|
return $this->env = array_merge($this->env, $name);
|
||||||
} elseif (empty($this->env)) {
|
|
||||||
$this->env = $_ENV;
|
|
||||||
}
|
}
|
||||||
return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter);
|
return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter);
|
||||||
}
|
}
|
||||||
@@ -891,9 +900,7 @@ class Request
|
|||||||
*/
|
*/
|
||||||
public function header($name = '', $default = null)
|
public function header($name = '', $default = null)
|
||||||
{
|
{
|
||||||
if (is_array($name)) {
|
if (empty($this->header)) {
|
||||||
return $this->header = array_merge($this->header, $name);
|
|
||||||
} elseif (empty($this->header)) {
|
|
||||||
$header = [];
|
$header = [];
|
||||||
$server = $this->server ?: $_SERVER;
|
$server = $this->server ?: $_SERVER;
|
||||||
foreach ($server as $key => $val) {
|
foreach ($server as $key => $val) {
|
||||||
@@ -910,6 +917,9 @@ class Request
|
|||||||
}
|
}
|
||||||
$this->header = array_change_key_case($header);
|
$this->header = array_change_key_case($header);
|
||||||
}
|
}
|
||||||
|
if (is_array($name)) {
|
||||||
|
return $this->header = array_merge($this->header, $name);
|
||||||
|
}
|
||||||
if ('' === $name) {
|
if ('' === $name) {
|
||||||
return $this->header;
|
return $this->header;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user