数据基础验证-检测字符串长度.

@param string $value     需要验证的值
@param int    $parameter 参数

@return bool
496762
public function isLength($value, $parameter)
    {
        $min = $parameter[0];
        $max = $parameter[1];
        if ($min != 0 && strlen($value) < $min) {
            return false;
        }
        if ($max != 0 && strlen($value) > $max) {
            return false;
        }

        return true;
    }
438137
public function setString(string $value, int $expire = 0): bool
    {
        $handle = $this->handle;

        //覆盖并设置生存时间
        if ($expire) {
            return $handle->setex($this->name, $expire, $value);
        }

        //仅覆盖
        return $handle->set($this->name, $value);
    }
1302281
protected function _validate_in($value, $parameter)
    {
        return in_array($value, preg_split('#[\s,]+#', $parameter, -1, PREG_SPLIT_NO_EMPTY), false) ? $value : null;
    }
1004631
public function bindValue($parameter = null, $value = null, $type = null)
    {
        parent::bindValue($parameter, $value, $type);
        
        return $this;
    }
933940
protected function _validate_exists($value, $parameter = null)
    {
        $context = $this->_context;

        if (!$value) {
            return $value;
        }
        $field = $context->field;
        if ($parameter) {
            $className = $parameter;
        } else {
            $modelName = get_class($context->model);
            if (preg_match('#^(.*)_id$#', $field, $match)) {
                $className = substr($modelName, 0, strrpos($modelName, '\\') + 1) . Text::camelize($match[1]);
                if (!class_exists($className)) {
                    $className = $this->alias->get('@ns.app') . '\\Models\\' . Text::camelize($match[1]);
                }
            } else {
                throw new InvalidValueException(['validate `:field` field failed: related model class name is not provided', 'field' => $field]);
            }
        }

        if (!class_exists($className)) {
            throw new InvalidValueException(['validate `:1` field failed: related `:2` model class is not exists.', $field, $className]);
        }

        /**
         * @var \ManaPHP\Model $model
         * @var \ManaPHP\Model $className
         */
        $model = new $className;
        return $className::exists([$model->getPrimaryKey() => $value]) ? $value : null;
    }
553141
protected function _validate_const($value, $parameter = null)
    {
        $context = $this->_context;

        $model = $context->model;
        $constants = $model::consts($parameter ?: $context->field);
        if (isset($constants[$value])) {
            return $value;
        } else {
            return ($r = array_search($value, $constants, true)) !== false ? $r : null;
        }
    }
1133595
function is_valid_parameter($parameter, $value) {

        if(is_array($value)) {
            if(!iCalendar_parameter::multiple_values_allowed($parameter)) {
                return false;
            }
            foreach($value as $item) {
                if(!iCalendar_parameter::is_valid_value($this, $parameter, $item)) {
                    return false;
                }
            }
            return true;
        }

        return iCalendar_parameter::is_valid_value($this, $parameter, $value);
    }
340418
public function isScenarioParameter($value, $checkExp = false) {
        if ($this->scenarioParameters === null) {
            $this->initParameters();
        }
        $result = isset($this->scenarioParameters[$value]);
        if (!$result) {
            if (substr($value, 0, 1) === "%" && substr($value, strlen($value) - 1, 1) === "%") {
                $result = true;
            }
        }
        if (!$result && $checkExp === true) {
            foreach ($this->scenarioParameters as $key => $v) {
                if (preg_match("/" . $key . "/", $value)) {
                    $result = true;
                    break;
                }
            }
        }
        return $result;
    }
29518
public function isBetween($value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'between');
        $size = $this->getSize($value);

        return $size >= $parameters[0] && $size <= $parameters[1];
    }
1315536
private function type($value, $type) {
        
        switch (func_num_args()) {
            case 0 :
            case 1 :
                return false;
            case 2 :
                // 二个参数时, 才执行正常处理逻辑
                
                if (is_array($type)) {
                    foreach ( $type as $t ) {
                        if ($this -> type($value, $t)) {
                            return true;
                        }
                    }
                    return false;
                }
                
                $t = strtolower(gettype($value));
                $type = strtolower($type);
                
                if ($type == $t) {
                    return true;
                } else if ($type == 'mixed') {
                    return true;
                } else {
                    switch ($t) {
                        case "integer" :
                            if ($type == 'int') {
                                return true;
                            }
                        case "double" :
                            return $type == 'number';
                        case "boolean" :
                            return $type == 'bool';
                        case "user function" :
                            return $type == 'function';
                        case "string" :
                        case "array" :
                        case "object" :
                        case "resource" :
                        case "null" :
                        case "unknown type" :
                        default :
                            return false;
                    }
                }
                return false;
            default :
                // 多于两个参数,认为第二个及其后的统统为可能的值.
                $varList = func_get_args();
                $value = array_shift($varList);
                
                return $this -> type($value, $varList);
        }
    
    }
985013
protected function parseParameter($value, ReflectionParameter $parameter) {
	    if (!$parameter->hasType()) {
	        return $value;
        }
        if ($parameter->getType() == 'int') {
	        return intval($value);
        }
        return $value;
    }
783170
public function isSize($value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'size');

        return $this->getSize($value) == $parameters[0];
    }
935000
private function setPayloadParameter(string $parameter, $value): void
    {
        $this->checkParameterType($value);

        $this->defaultSetPayloadParameter($parameter, $value);
    }
1304039
public function isDigitsBetween($value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'digits_between');

        $length = strlen((string)$value);

        return !preg_match('/[^0-9]/', $value)
               && $length >= $parameters[0] && $length <= $parameters[1];
    }
1294049
public function validateIn($attribute, $value, $parameters)
    {
        if (is_array($value) && $this->hasRule($attribute, 'Array')) {
            foreach ($value as $element) {
                if (is_array($element)) {
                    return false;
                }
            }

            return count(array_diff($value, $parameters)) === 0;
        }

        return ! is_array($value) && in_array((string) $value, $parameters);
    }
1120792
private function validateParameter(string $parameter): bool
    {
        $properties = explode('=', $parameter);

        return 2 != count($properties) || strtolower($properties[0]) === static::BINARY_PARAMETER;
    }
315352
protected function isRequiredWith($value, $parameters)
    {
        if (!$this->allFailingRequired($parameters)) {
            return $this->isRequired($value);
        }

        return true;
    }