只验证一条信息
@param $value
@param $rule
@param array $message
@return bool
485843
public function one($value,$rule,$message=[])
    {
        $this->clear();
        $this->from['one']=$value;
        $value=strtolower($rule);
        if(strpos($value, '|')===false){
            $rule=[$value];
        }else{
            $tmp=explode('|',$value);
            $rule=$tmp;
        }
        foreach ($message as $key=>$value){
            $keys=strtolower($key);
            $this->msge['one'][$keys]=$value;
        }
        return $this->checks('one',$rule);
    }
200502
protected function length($value, $rule)
    {
        if (is_array($value)) {
            $length=count($value);
        } elseif ($value instanceof File) {
            $length=$value->getSize();
        } else {
            $length=mb_strlen((string) $value);
        }

        if (strpos($rule, ',')) {
            // 长度区间
            list($min, $max)=explode(',', $rule);
            return $length >= $min && $length <= $max;
        } else {
            // 指定长度
            return $length == $rule;
        }
    }
893762
private function validate($value, $rule, $param)
    {
        if (in_array($rule, $this->reserved)) {
            return array($value, null);
        }
        if (is_array($value) && !in_array($rule, array('minLength', 'maxLength', 'rangeLength'))) {
            $values = $value;
            $errors = array();
            foreach ($values as $key => $value) {
                list($value, $error) = $this->validate($value, $rule, $param);
                $values[$key] = $value;
                if ($error) {
                    $errors[$key] = $error;
                }
            }

            return array($values, !empty($errors) ? array_shift($errors) : null);
        }
        $error = null;
        if ($rule == 'remote') {
            if ('true' != $result = $this->remote($value, $param)) {
                $error = ($result == 'false') ? $this->errorMessage($rule, $param) : $result;
            }
        } elseif (isset($this->rules[$rule]) && is_callable($this->rules[$rule])) {
            if (!is_bool($result = $this->rules[$rule]($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        } elseif (in_array($rule, $this->methods)) {
            if (!is_bool($result = self::$rule($value, $param))) {
                $value = $result;
            }
            if ($result === false) {
                $error = $this->errorMessage($rule, $param);
            }
        }

        return array($value, $error);
    }
187240
private function validateAgainstExpression( $field, $value, $rule, $message = null )
    {
        if (preg_match($this->expressions[ $rule ], $value)) {
            return true;
        }

        if (!$message) {
            $message = $this->error_messages[ $rule ];
        }

        static::$errors[ $field ] = $message;

        return false;
    }
920279
public function isValidValue($rules, $value) {
        $result = [];
        foreach ($rules as $rule) {
            $parameters = $rule;
            $name       = array_shift($parameters);
            $valid      = $this->isValidRule($name, $parameters, $value);
            if ($valid !== null) {
                $result[] = $valid;
            }
        }
        return $result;
    }
827935
private function validateItem($value, $rules)
    {
        if (!$value && strlen($value) == 0 && empty($rules['required'])) {
            return true;
        }

        //
        unset($rules['message'], $rules['trigger']);

        foreach ($rules as $ruleName => $ruleValue) {
            if (!call_user_func("static::{$ruleName}", $value, $ruleValue)) {
                return false;
            }
        }
    }
764662
public function match($value, $pattern, $message = '')
    {
        $this->assertion->setActual($value);

        return $this->assertion->to->match($pattern, $message);
    }
322879
public static function regexVerify($value, $rule)
    {
        $value = trim($value);
        $validate = array(
            'require' => '/\S+/',
            'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
            // 'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
            'url' => '/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i',
            'currency' => '/^\d+(\.\d+)?$/',
            # 货币
            'number' => '/^\d+$/',
            'zip' => '/^\d{6}$/',
            'integer' => '/^[-\+]?\d+$/',
            'double' => '/^[-\+]?\d+(\.\d+)?$/',
            'english' => '/^[A-Za-z]+$/',
        );

        // 检查是否有内置的正则表达式
        if (isset($validate[strtolower($rule)])) {
            $rule = $validate[strtolower($rule)];
        }

        return preg_match($rule, $value) === 1;
    }
1324837
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]);
    }
1298077
protected function gt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value > $val;
    }
133043
public static function getRule($ruleName) {

		if (isset(self::$rules[$ruleName])) {
			return self::$rules[$ruleName];
		}

		return false;

	}
109770
public function set_message($rule, $message)
	{
		if ($message !== null)
		{
			$this->error_messages[$rule] = $message;
		}
		else
		{
			unset($this->error_messages[$rule]);
		}

		return $this;
	}
985992
protected function method($value, $rule)
    {
        $method=Request::instance()->method();
        return strtoupper($rule) == $method;
    }
777231
public function regex($value,$rule) {
        $validate = array(
            'require'   =>  '/\S+/',
            'email'     =>  '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
            'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
            'currency'  =>  '/^\d+(\.\d+)?$/',
            'number'    =>  '/^\d+$/',
            'zip'       =>  '/^\d{6}$/',
            'integer'   =>  '/^[-\+]?\d+$/',
            'double'    =>  '/^[-\+]?\d+(\.\d+)?$/',
            'english'   =>  '/^[A-Za-z]+$/',
        );
        // 检查是否有内置的正则表达式
        if(isset($validate[strtolower($rule)]))
            $rule       =   $validate[strtolower($rule)];
        return preg_match($rule,$value)===1;
    }
862352
public function run( $field, $value, $message = null ) {

        $this->field   = $field;
        $this->message = $message;

        if ( ! $this->fieldKey || ! $this->fields ) {
            return false;
        }

        if ( $this->fields[ $this->fieldKey ] == $value ) {
            return true;
        }

        return false;
    }
1053397
public function parse($value, $rule) {
        $rs = $value;

        if (!is_array($rs)) {
            $ruleFormat = !empty($rule['format']) ? strtolower($rule['format']) : '';
            if ($ruleFormat == 'explode') {
                $rs = explode(isset($rule['separator']) ? $rule['separator'] : ',', $rs);
            } else if ($ruleFormat == 'json') {
                $rs = json_decode($rs, TRUE);

                if (!empty($value) && $rs === NULL) {
                    $message = isset($rule['message']) 
                        ? \PhalApi\T($rule['message']) 
                        : \PhalApi\T('{name} illegal json data', array('name' => $rule['name']));
                    throw new BadRequestException($message);
                }
            } else {
                $rs = array($rs);
            }
        }

        $this->filterByRange(count($rs), $rule);

        return $rs;
    }
274534
protected function checkItem($field, $value, $rules, $data, $title='', $msg=[])
    {
        // 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...]
        if (is_string($rules)) {
            $rules=explode('|', $rules);
        }
        $i=0;
        foreach ($rules as $key => $rule) {
            if ($rule instanceof \Closure) {
                $result=call_user_func_array($rule, [$value, $data]);
                $info=is_numeric($key) ? '' : $key;
            } else {
                // 判断验证类型
                if (is_numeric($key)) {
                    if (strpos($rule, ':')) {
                        list($type, $rule)=explode(':', $rule, 2);
                        if (isset($this->alias[$type])) {
                            // 判断别名
                            $type=$this->alias[$type];
                        }
                        $info=$type;
                    } elseif (method_exists($this, $rule)) {
                        $type=$rule;
                        $info=$rule;
                        $rule='';
                    } else {
                        $type='is';
                        $info=$rule;
                    }
                } else {
                    $info=$type=$key;
                }

                // 如果不是require 有数据才会行验证
                if (0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) {
                    // 验证类型
                    $callback=isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];
                    // 验证数据
                    $result=call_user_func_array($callback, [$value, $rule, $data, $field, $title]);
                } else {
                    $result=true;
                }
            }

            if (false === $result) {
                // 验证失败 返回错误信息
                if (isset($msg[$i])) {
                    $message=$msg[$i];
                    if (is_string($message) && strpos($message, '{%') === 0) {
                        $message=Lang::get(substr($message, 2, -1));
                    }
                } else {
                    $message=$this->getRuleMsg($field, $title, $info, $rule);
                }
                return $message;
            } elseif (true !== $result) {
                // 返回自定义错误信息
                if (is_string($result) && false !== strpos($result, ':')) {
                    $result=str_replace([':attribute', ':rule'], [$title, (string) $rule], $result);
                }
                return $result;
            }
            $i++;
        }
        return $result;
    }