From 51eb09ef5a29ec0cf0280289c8824d4f977a7794 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Mar 2016 10:38:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0requireCallback=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Loader.php | 3 --- library/think/Validate.php | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/library/think/Loader.php b/library/think/Loader.php index 82a890af..beb4b4f8 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -337,9 +337,6 @@ class Loader $module = APP_MULTI_MODULE ? MODULE_NAME : ''; } $class = self::parseClass($module, $layer, $name); - // controller_load - APP_HOOK && Hook::listen('controller_load', $class); - if (class_exists($class)) { $action = new $class; $_instance[$name . $layer] = $action; diff --git a/library/think/Validate.php b/library/think/Validate.php index cc7e5576..9fc5c1f1 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -665,6 +665,24 @@ class Validate } } + /** + * 通过回调方法验证某个字段是否必须 + * @access protected + * @param mixed $value 字段值 + * @param mixed $rule 验证规则 + * @param array $data 数据 + * @return bool + */ + protected function requireCallback($value, $rule, $data) + { + $result = call_user_func_array($rule, [$value, $data]); + if ($result) { + return !empty($value); + } else { + return true; + } + } + /** * 验证某个字段有值的情况下必须 * @access protected From c20f449783dfc0affc83e89f7740cadde53e6462 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Mar 2016 10:51:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84validate=E7=B1=BB?= =?UTF-8?q?=E7=9A=84ip=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index 9fc5c1f1..52330ade 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -548,6 +548,21 @@ class Validate return checkdnsrr($value, $rule); } + /** + * 验证是否有效IP + * @access protected + * @param mixed $value 字段值 + * @param mixed $rule 验证规则 ipv4 ipv6 + * @return bool + */ + protected function ip($value, $rule) + { + if (!in_array($rule, ['ipv4', 'ipv6'])) { + $rule = 'ipv4'; + } + return $this->filter($value, FILTER_VALIDATE_IP, 'ipv6' == $rule ? FILTER_FLAG_IPV6 : FILTER_FLAG_IPV4); + } + /** * 验证请求类型 * @access protected