From 91799e1c36eeb33e6e84713509f3ad1bcaa8748e Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Wed, 21 Mar 2018 20:43:55 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=9C=BA=E5=88=B6=EF=BC=8C=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/behavior/RequestFilter.php | 8 +-- thinkphp/library/think/Request.php | 84 ++++++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/application/api/behavior/RequestFilter.php b/application/api/behavior/RequestFilter.php index fc15161..cb10925 100644 --- a/application/api/behavior/RequestFilter.php +++ b/application/api/behavior/RequestFilter.php @@ -76,16 +76,16 @@ class RequestFilter { switch ($method) { case 'GET': - $request->get($newData); + $request->forceGet($newData); break; case 'POST': - $request->post($newData); + $request->forcePost($newData); break; case 'DELETE': - $request->delete($newData); + $request->forceDelete($newData); break; case 'PUT': - $request->put($newData); + $request->forcePut($newData); break; } ApiLog::setRequestAfterFilter($newData); diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php index 4a40d22..d49295d 100644 --- a/thinkphp/library/think/Request.php +++ b/thinkphp/library/think/Request.php @@ -1645,4 +1645,88 @@ class Request { return isset($this->bind[$name]); } + + /** + * 强制覆盖GET参数 + * @access public + * @param string|array $name 变量名 + * @param mixed $default 默认值 + * @param string|array $filter 过滤方法 + * @return mixed + */ + public function forceGet($name = '', $default = null, $filter = '') + { + if (empty($this->get)) { + $this->get = $_GET; + } + if (is_array($name)) { + $this->param = []; + return $this->get = $name; + } + return $this->input($this->get, $name, $default, $filter); + } + + /** + * 强制覆盖POST参数 + * @access public + * @param string $name 变量名 + * @param mixed $default 默认值 + * @param string|array $filter 过滤方法 + * @return mixed + */ + public function forcePost($name = '', $default = null, $filter = '') + { + if (empty($this->post)) { + $content = $this->input; + if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) { + $this->post = (array) json_decode($content, true); + } else { + $this->post = $_POST; + } + } + if (is_array($name)) { + $this->param = []; + return $this->post = $name; + } + return $this->input($this->post, $name, $default, $filter); + } + + /** + * 强制覆盖PUT参数 + * @access public + * @param string|array $name 变量名 + * @param mixed $default 默认值 + * @param string|array $filter 过滤方法 + * @return mixed + */ + public function forcePut($name = '', $default = null, $filter = '') + { + if (is_null($this->put)) { + $content = $this->input; + if (false !== strpos($this->contentType(), 'application/json')) { + $this->put = (array) json_decode($content, true); + } else { + parse_str($content, $this->put); + } + } + if (is_array($name)) { + $this->param = []; + return $this->put = $name; + } + + return $this->input($this->put, $name, $default, $filter); + } + + /** + * 强制覆盖DELETE参数 + * @access public + * @param string|array $name 变量名 + * @param mixed $default 默认值 + * @param string|array $filter 过滤方法 + * @return mixed + */ + public function forceDelete($name = '', $default = null, $filter = '') + { + return $this->forcePut($name, $default, $filter); + } }