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..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 @@ -665,6 +680,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