From c323f5e2556acafe77f7345329e19b68ddd29371 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 20 Mar 2016 09:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=B1=BB=E5=9E=8B=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8=E5=88=AB=E5=90=8D?= =?UTF-8?q?=20=E4=BE=8B=E5=A6=82=20'age'=3D>'>:10'=20=E5=92=8C=20'age'=3D>?= =?UTF-8?q?'gt:10'=20=E7=AD=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index 6a8259b5..9e1c33f2 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -19,6 +19,11 @@ class Validate // 自定义的验证类型 protected $type = []; + // 验证类型别名 + protected $alias = [ + '>' => 'gt', '>=' => 'egt', '<' => 'lt', '<=' => 'elt', '=' => 'eq', 'same' => 'eq', + ]; + // 当前验证的规则 protected $rule = []; @@ -271,7 +276,11 @@ class Validate // 判断验证类型 if (is_numeric($key) && strpos($rule, ':')) { list($type, $rule) = explode(':', $rule, 2); - $info = $type; + if (isset($this->alias[$type])) { + // 判断别名 + $type = $this->alias[$type]; + } + $info = $type; } elseif (is_numeric($key)) { $type = 'is'; $info = $rule; @@ -376,7 +385,7 @@ class Validate * @param mixed $rule 验证规则 * @return bool */ - public function same($value, $rule) + public function eq($value, $rule) { return $value == $rule; }