From 51eb09ef5a29ec0cf0280289c8824d4f977a7794 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Mar 2016 10:38:39 +0800 Subject: [PATCH] =?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