core/Validate.php
public static function checkValue($value, array $rules = null, array $message = null, string &$error)
    {
        if ($rules == null || count($rules) == 0) {
            return true;
        }
        $validFunc = isset($rules['validFunc']) ? $rules['validFunc'] : null;
        if ($validFunc && is_callable($validFunc)) {
            $err = $validFunc($value);
            if (!empty($err)) {
                $error = $err;
                return false;
            }
        }
        if ($message == null) {
            $message = [];
        }
        //获取
        $tempMegs = [];
        foreach ($message as $type => $msg) {
            $realType = Validate::getRealType($type);
            $tempMegs[$realType] = $msg;
        }
        $message = $tempMegs;
        $tempRules = [];
        foreach ($rules as $type => $args) {
            $realType = Validate::getRealType($type);
            $tempRules[$realType] = $args;
        }
        $rules = $tempRules;
        //验证非空
        if (isset($rules['required']) && $rules['required']) {
            $func = Validate::getFunc('required');
            $r = call_user_func_array($func, [$value]);
            if (!$r) {
                $error = (isset($message['required']) ? $message['required'] : (isset(Validate::$default_errors['required']) ? Validate::$default_errors['required'] : '必填项'));
                return false;
            }
            unset($rules['required']);
        }
        //如果是数组直接放弃
        if (is_array($value) || $value instanceof \stdClass) {
            return true;
        }

        if (strlen($value) > 0 || (isset($rules['force']) && $rules['force'])) {
            unset($rules['force']);
            foreach ($rules as $type => $args) {
                if (!is_array($args)) {
                    $args = [$args];
                }
                $param = array_slice($args, 0);
                array_unshift($args, $value);
                $func = Validate::getFunc($type);
                if ($func == null) {
                    continue;
                }
                $out = call_user_func_array($func, $args);
                if (is_bool($out)) {
                    if ($out) {
                        continue;
                    }
                    $err = (isset($message[$type]) ? $message[$type] : (isset(Validate::$default_errors[$type]) ? Validate::$default_errors[$type] : '格式错误'));
                    $error = Validate::format($err, $param);
                    return false;
                }
                if (is_array($out) && isset($out['status']) && !$out['status'] && !empty($out['error'])) {
                    $error = Validate::format($out['error'], $param);
                    return false;
                }
            }
        }
        return true;
    }
public static function checkValue($value, array $rules = null, array $message = null, string &$error)
    {
        if ($rules == null || count($rules) == 0) {
            return true;
        }
        $validFunc = isset($rules['validFunc']) ? $rules['validFunc'] : null;
        if ($validFunc && is_callable($validFunc)) {
            $err = $validFunc($value);
            if (!empty($err)) {
                $error = $err;
                return false;
            }
        }
        if ($message == null) {
            $message = [];
        }
        //获取
        $tempMegs = [];
        foreach ($message as $type => $msg) {
            $realType = Validate::getRealType($type);
            $tempMegs[$realType] = $msg;
        }
        $message = $tempMegs;
        $tempRules = [];
        foreach ($rules as $type => $args) {
            $realType = Validate::getRealType($type);
            $tempRules[$realType] = $args;
        }
        $rules = $tempRules;
        //验证非空
        if (isset($rules['required']) && $rules['required']) {
            $func = Validate::getFunc('required');
            $r = call_user_func_array($func, [$value]);
            if (!$r) {
                $error = (isset($message['required']) ? $message['required'] : (isset(Validate::$default_errors['required']) ? Validate::$default_errors['required'] : '必填项'));
                return false;
            }
            unset($rules['required']);
        }
        //如果是数组直接放弃
        if (is_array($value) || $value instanceof \stdClass) {
            return true;
        }

        if (strlen($value) > 0 || (isset($rules['force']) && $rules['force'])) {
            unset($rules['force']);
            foreach ($rules as $type => $args) {
                if (!is_array($args)) {
                    $args = [$args];
                }
                $param = array_slice($args, 0);
                array_unshift($args, $value);
                $func = Validate::getFunc($type);
                if ($func == null) {
                    continue;
                }
                $out = call_user_func_array($func, $args);
                if (is_bool($out)) {
                    if ($out) {
                        continue;
                    }
                    $err = (isset($message[$type]) ? $message[$type] : (isset(Validate::$default_errors[$type]) ? Validate::$default_errors[$type] : '格式错误'));
                    $error = Validate::format($err, $param);
                    return false;
                }
                if (is_array($out) && isset($out['status']) && !$out['status'] && !empty($out['error'])) {
                    $error = Validate::format($out['error'], $param);
                    return false;
                }
            }
        }
        return true;
    }
验证单个错误
@param array $value
@param array $rule