From 53329b79b6d46d43888221a3206dfd08c8fc6407 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 9 Nov 2016 12:17:42 +0800 Subject: [PATCH] =?UTF-8?q?Requesst=E7=B1=BB=E7=9A=84Input=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8Cinput=E5=8A=A9=E6=89=8B=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E7=9A=84filter=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E5=85=A5null=20=E8=A1=A8=E7=A4=BA=E5=BD=93=E5=89=8D=E4=B8=8D?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper.php | 2 +- library/think/Request.php | 40 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/helper.php b/helper.php index 451d3344..b81970c7 100644 --- a/helper.php +++ b/helper.php @@ -117,7 +117,7 @@ if (!function_exists('input')) { * @param string $filter 过滤方法 * @return mixed */ - function input($key = '', $default = null, $filter = null) + function input($key = '', $default = null, $filter = '') { if (0 === strpos($key, '?')) { $key = substr($key, 1); diff --git a/library/think/Request.php b/library/think/Request.php index b55db39c..8a354633 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -609,7 +609,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function param($name = '', $default = null, $filter = null) + public function param($name = '', $default = null, $filter = '') { if (empty($this->param)) { $method = $this->method(true); @@ -646,7 +646,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function route($name = '', $default = null, $filter = null) + public function route($name = '', $default = null, $filter = '') { if (is_array($name)) { $this->param = []; @@ -663,7 +663,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function get($name = '', $default = null, $filter = null) + public function get($name = '', $default = null, $filter = '') { if (empty($this->get)) { $this->get = $_GET; @@ -683,7 +683,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function post($name = '', $default = null, $filter = null) + public function post($name = '', $default = null, $filter = '') { if (empty($this->post)) { $this->post = $_POST; @@ -703,7 +703,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function put($name = '', $default = null, $filter = null) + public function put($name = '', $default = null, $filter = '') { if (is_null($this->put)) { $content = $this->input; @@ -729,7 +729,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function delete($name = '', $default = null, $filter = null) + public function delete($name = '', $default = null, $filter = '') { return $this->put($name, $default, $filter); } @@ -742,7 +742,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function patch($name = '', $default = null, $filter = null) + public function patch($name = '', $default = null, $filter = '') { return $this->put($name, $default, $filter); } @@ -754,7 +754,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function request($name = '', $default = null, $filter = null) + public function request($name = '', $default = null, $filter = '') { if (empty($this->request)) { $this->request = $_REQUEST; @@ -774,7 +774,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function session($name = '', $default = null, $filter = null) + public function session($name = '', $default = null, $filter = '') { if (empty($this->session)) { $this->session = Session::get(); @@ -793,7 +793,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function cookie($name = '', $default = null, $filter = null) + public function cookie($name = '', $default = null, $filter = '') { if (empty($this->cookie)) { $this->cookie = $_COOKIE; @@ -812,7 +812,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function server($name = '', $default = null, $filter = null) + public function server($name = '', $default = null, $filter = '') { if (empty($this->server)) { $this->server = $_SERVER; @@ -890,7 +890,7 @@ class Request * @param string|array $filter 过滤方法 * @return mixed */ - public function env($name = '', $default = null, $filter = null) + public function env($name = '', $default = null, $filter = '') { if (empty($this->env)) { $this->env = $_ENV; @@ -949,7 +949,7 @@ class Request * @param string|array $filter 过滤函数 * @return mixed */ - public function input($data = [], $name = '', $default = null, $filter = null) + public function input($data = [], $name = '', $default = null, $filter = '') { if (false === $name) { // 获取原始数据 @@ -978,13 +978,17 @@ class Request } // 解析过滤器 - $filter = $filter ?: $this->filter; - - if (is_string($filter)) { - $filter = explode(',', $filter); + if (is_null($filter)) { + $filter = []; } else { - $filter = (array) $filter; + $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);