From f6a8a2804fb08d1ab2fc3952617fd461220e7cd7 Mon Sep 17 00:00:00 2001 From: lilwil Date: Mon, 20 Mar 2017 13:13:22 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=AF=94=E8=BE=83=E6=94=AF=E6=8C=81=E5=AF=B9=E6=AF=94=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 718ed7a1..89b2f11a 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -456,11 +456,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ protected function egt($value, $rule) { - return $value >= $rule; + return !is_null($this->getDataValue($data, $rule)) && $value >= $this->getDataValue($data, $rule); } /** @@ -468,11 +469,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ protected function gt($value, $rule) { - return $value > $rule; + return !is_null($this->getDataValue($data, $rule)) && $value > $this->getDataValue($data, $rule); } /** @@ -480,11 +482,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ protected function elt($value, $rule) { - return $value <= $rule; + return !is_null($this->getDataValue($data, $rule)) && $value <= $this->getDataValue($data, $rule); } /** @@ -492,11 +495,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ - protected function lt($value, $rule) + protected function lt($value, $rule, $data) { - return $value < $rule; + return !is_null($this->getDataValue($data, $rule)) && $value < $this->getDataValue($data, $rule); } /** @@ -504,11 +508,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ - protected function eq($value, $rule) + protected function eq($value, $rule, $data) { - return $value == $rule; + return !is_null($this->getDataValue($data, $rule)) && $value == $this->getDataValue($data, $rule); } /** @@ -1190,8 +1195,8 @@ class Validate // 支持二维数组验证 list($name1, $name2) = explode('.', $key); $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; - } else { - $value = isset($data[$key]) ? $data[$key] : null; + } else { + $value = is_numeric($key) ? $key : (isset($data[$key]) ? $data[$key] : null); } return $value; } From 8e8ac352a4b3b3610a448c4724cfc23a543440e5 Mon Sep 17 00:00:00 2001 From: lilwil Date: Mon, 20 Mar 2017 13:14:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 89b2f11a..328a7aaa 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -459,7 +459,7 @@ class Validate * @param array $data 数据 * @return bool */ - protected function egt($value, $rule) + protected function egt($value, $rule, $data) { return !is_null($this->getDataValue($data, $rule)) && $value >= $this->getDataValue($data, $rule); } @@ -472,7 +472,7 @@ class Validate * @param array $data 数据 * @return bool */ - protected function gt($value, $rule) + protected function gt($value, $rule, $data) { return !is_null($this->getDataValue($data, $rule)) && $value > $this->getDataValue($data, $rule); } @@ -485,7 +485,7 @@ class Validate * @param array $data 数据 * @return bool */ - protected function elt($value, $rule) + protected function elt($value, $rule, $data) { return !is_null($this->getDataValue($data, $rule)) && $value <= $this->getDataValue($data, $rule); } From f439a84165f2c813503e2c5683fdebb47c7ce83c Mon Sep 17 00:00:00 2001 From: lilwil Date: Mon, 20 Mar 2017 13:44:36 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 328a7aaa..fd88bb9d 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -508,12 +508,11 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 - * @param array $data 数据 * @return bool */ - protected function eq($value, $rule, $data) + protected function eq($value, $rule) { - return !is_null($this->getDataValue($data, $rule)) && $value == $this->getDataValue($data, $rule); + return $value == $rule; } /** From b2e59eb4c7e2a1e48347d2f2baacd6f912ac2f8c Mon Sep 17 00:00:00 2001 From: lilwil Date: Mon, 20 Mar 2017 14:17:50 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index fd88bb9d..20c1ed22 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1179,25 +1179,28 @@ class Validate public function getError() { return $this->error; - } - - /** - * 获取数据值 - * @access protected - * @param array $data 数据 - * @param string $key 数据标识 支持二维 - * @return mixed - */ - protected function getDataValue($data, $key) - { - if (strpos($key, '.')) { - // 支持二维数组验证 - list($name1, $name2) = explode('.', $key); - $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; + } + + /** + * 获取数据值 + * + * @access protected + * @param array $data + * 数据 + * @param string $key + * 数据标识 支持二维 + * @return mixed + */ + protected function getDataValue($data, $key) + { + if (strpos($key, '.')) { + // 支持二维数组验证 + list ($name1, $name2) = explode('.', $key); + $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; } else { - $value = is_numeric($key) ? $key : (isset($data[$key]) ? $data[$key] : null); - } - return $value; + $value = is_numeric($key) ? $key : (isset($data[$key]) ? $data[$key] : null); + } + return $value; } /** From 552d564cd60b6a436e584cf4facbeecd239c28d1 Mon Sep 17 00:00:00 2001 From: lilwil Date: Mon, 20 Mar 2017 14:20:10 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 20c1ed22..ca425496 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -1181,25 +1181,22 @@ class Validate return $this->error; } - /** - * 获取数据值 - * - * @access protected - * @param array $data - * 数据 - * @param string $key - * 数据标识 支持二维 - * @return mixed - */ - protected function getDataValue($data, $key) - { - if (strpos($key, '.')) { - // 支持二维数组验证 - list ($name1, $name2) = explode('.', $key); - $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; - } else { - $value = is_numeric($key) ? $key : (isset($data[$key]) ? $data[$key] : null); - } + /** + * 获取数据值 + * @access protected + * @param array $data 数据 + * @param string $key 数据标识 支持二维 + * @return mixed + */ + protected function getDataValue($data, $key) + { + if (strpos($key, '.')) { + // 支持二维数组验证 + list($name1, $name2) = explode('.', $key); + $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; + } else { + $value = is_numeric($key) ? $key : (isset($data[$key]) ? $data[$key] : null); + } return $value; }