验证是否和某个字段的值一致
@access public
@param  mixed  $value 字段值
@param  mixed  $rule  验证规则
@param  array  $data  数据
@param  string $field 字段名
@return bool
558024
public function confirm( $value, $rule, $data = [], $field = '' )
	{
		if( '' == $rule ){
			if( strpos( $field, '_confirm' ) ){
				$rule = strstr( $field, '_confirm', true );
			} else{
				$rule = $field.'_confirm';
			}
		}
		return $this->getDataValue( $data, $rule ) === $value;
	}
230423
public function check($value,$rule,$type='regex'){
        $type   =   strtolower(trim($type));
        switch($type) {
            case 'in': // 验证是否在某个指定范围之内 逗号分隔字符串或者数组
            case 'notin':
                $range   = is_array($rule)? $rule : explode(',',$rule);
                return $type == 'in' ? in_array($value ,$range) : !in_array($value ,$range);
            case 'between': // 验证是否在某个范围
            case 'notbetween': // 验证是否不在某个范围            
                if (is_array($rule)){
                    $min    =    $rule[0];
                    $max    =    $rule[1];
                }else{
                    list($min,$max)   =  explode(',',$rule);
                }
                return $type == 'between' ? $value>=$min && $value<=$max : $value<$min || $value>$max;
            case 'equal': // 验证是否等于某个值
            case 'notequal': // 验证是否等于某个值            
                return $type == 'equal' ? $value == $rule : $value != $rule;
            case 'length': // 验证长度
                $length  =  mb_strlen($value,'utf-8'); // 当前数据长度
                if(strpos($rule,',')) { // 长度区间
                    list($min,$max)   =  explode(',',$rule);
                    return $length >= $min && $length <= $max;
                }else{// 指定长度
                    return $length == $rule;
                }
            case 'expire':
                list($start,$end)   =  explode(',',$rule);
                if(!is_numeric($start)) $start   =  strtotime($start);
                if(!is_numeric($end)) $end   =  strtotime($end);
                return NOW_TIME >= $start && NOW_TIME <= $end;
            case 'ip_allow': // IP 操作许可验证
                return in_array(get_client_ip(),explode(',',$rule));
            case 'ip_deny': // IP 操作禁止验证
                return !in_array(get_client_ip(),explode(',',$rule));
            case 'regex':
            default:    // 默认使用正则验证 可以使用验证类中定义的验证名称
                // 检查附加规则
                return $this->regex($value,$rule);
        }
    }
6350
public function rules($field)
    {
        return (isset($this->data[$field]) && $validate = $this->data[$field]['validate']) ? $validate : array();
    }
1310982
public function partition($data, $field, $rule = [])
    {
        $this->options['table'] = $this->getPartitionTableName($data, $field, $rule);

        return $this;
    }
609242
protected function egt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value >= $val;
    }
973655
protected function requireWith($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);
        if (!empty($val))
        {
            return !empty($value) || '0' == $value;
        }
        else
        {
            return true;
        }
    }
91640
public function set_select($field = '', $value = '', $default = false)
    {
        if (!$this->ran()) {
            return ($default === true) ? ' selected="selected"' : '';
        }

        $field = (isset($this->_field_data[$field]['postdata']) ? $this->_field_data[$field]['postdata']: '');
        $value = (string) $value;
        if (is_array($field)) {
        // Note: in_array('', array(0)) returns true, do not use it
            foreach ($field as $v) {
                if ($value === $v) {
                    return ' selected="selected"';
                }
            }

            return '';
        } elseif (($field === '' || $value === '') || ($field !== $value)) {
            return '';
        }

        return ' selected="selected"';
    }
1306671
protected function token($value, $rule, $data)
    {
        $rule=!empty($rule) ? $rule : '__token__';
        if (!isset($data[$rule]) || !Session::has($rule)) {
            // 令牌数据无效
            return false;
        }

        // 令牌验证
        if (isset($data[$rule]) && Session::get($rule) === $data[$rule]) {
            // 防止重复提交
            Session::delete($rule); // 验证完成销毁session
            return true;
        }
        // 开启TOKEN重置
        Session::delete($rule);
        return false;
    }
407298
public function compareFields($value, $field, $context) {
		if (!isset($context['data'][$field])) {
			return true;
		}
		if ($value === $context['data'][$field]) {
			return true;
		}

		return false;
	}
1367247
public static function required(Validator $validator, $data, $pattern, $rule)
    {
        // Check pattern is present
        if (!ArrDots::has($data, $pattern, $validator::WILD)) {
            $validator->addError($pattern, $rule);
        }

        // Check value is not null
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null !== $value) {
                continue;
            }

            $validator->addError($attribute, $rule);
        }
    }
1262137
public function parse($value, $rule) {

        $default = isset($rule['default']) ? $rule['default'] : NULL;
        $index = $rule['name'];
        $fileList = array();

        // 未上传 && (有默认值 || 非必须)
        if (!isset($_FILES[$index]) && ($default !== NULL || empty($rule['require']))) {
            return $default;
        }

        if (!isset($_FILES[$index]) || !is_array($_FILES[$index])) {
            $message = isset($rule['message'])
                ? \PhalApi\T($rule['message'])
                : \PhalApi\T('miss upload file: {file}', array('file' => $index));
            throw new BadRequestException($message);
        }

        if (is_array($_FILES[$index]['tmp_name'])) {
            $count = sizeof($_FILES[$index]['tmp_name']);

            for ($i = 0; $i < $count; $i++) {
                $file = array(
                    'name' => $_FILES[$index]['name'][$i],
                    'type' => $_FILES[$index]['type'][$i],
                    'tmp_name' => $_FILES[$index]['tmp_name'][$i],
                    'error' => $_FILES[$index]['error'][$i],
                    'size' => $_FILES[$index]['size'][$i]
                );

                $fileList[] = $this->parseOne($file, $rule);
            }
        } else {
            $file = array(
                'name' => $_FILES[$index]['name'],
                'type' => $_FILES[$index]['type'],
                'tmp_name' => $_FILES[$index]['tmp_name'],
                'error' => $_FILES[$index]['error'],
                'size' => $_FILES[$index]['size']
            );
            // 单个文件直接返回文件信息数组
            return $this->parseOne($file, $rule);
        }

        // 返回文件信息二维数组
        return $fileList;
    }
135964
protected function lt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value < $val;
    }
1143073
public function getFieldValue($field, $data = null)
    {
        if ($data !== null && isset($data[$field])) {
            return $data[$field];
        }
        if (isset($this->{$field})) {
            return $this->{$field};
        }
        return null;
    }
568484
final public function setRowFieldValue($field, $value)
    {

        //If value exists;
        if (array_key_exists($field, $this->schema)) {
            $this->schema[$field]->Value = $value;
            return true;
        }
        return false;
    }
596945
public function parse($value, $rule) {
        $rs = strval($this->filterByStrLen(strval($value), $rule));

        $this->filterByRegex($rs, $rule);

        return $rs;
    }
562311
public static function checkCompareValue($rule, $value)
    {
        if(isset($rule[0]) && '!' === $rule[0])
        {
            // 不等
            return $value !== $rule;
        }
        else
        {
            // 相等
            return $value === $rule;
        }
    }
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;
    }