校验规则

@param  array  $attributes
@param  string $name
@param  array  $parameters

@return bool
@throws \One\Validation\Exceptions\ValidationException
338490
protected function validate(array $attributes, string $name, array $parameters): bool
    {
        if (! isset($parameters['is']) &&
            ! isset($parameters['min']) &&
            ! isset($parameters['max'])
        ) {
            throw new ValidationException('长度限制条件必须填写');
        }

        $len = mb_strlen($attributes[$name]);

        if (isset($parameters['is'])) {
            if ($len === (int) $parameters['is']) {
                return true;
            }
        }

        if (isset($parameters['min']) && isset($parameters['max'])) {
            if ($len >= (int) $parameters['min'] && $len <= (int) $parameters['max']) {
                return true;
            }
        } elseif (isset($parameters['min'])) {
            if ($len >= (int) $parameters['min']) {
                return true;
            }
        } elseif (isset($parameters['max'])) {
            if ($len <= (int) $parameters['max']) {
                return true;
            }
        }

        $this->addError($name, $parameters, '%s 长度不符合');

        return false;
    }
360369
protected function validateIsbn($attribute, $value, $parameters)
    {
        // Prepare value for validation
        $value = str_replace([' ', '-', '‐', '.'], '', $value);

        // Length of value
        $length = strlen($value);

        // Validate either ISBN10 or ISBN13
        if ($length == 10) {
            return $this->validateIsbn10($attribute, $value, $parameters);
        } elseif ($length == 13) {
            return $this->validateIsbn13($attribute, $value, $parameters);
        }

        return false;
    }
535016
public function validateNameOnCreate($attribute, $value, $parameters)
    {
        $groupId = Input::get('group');
        $typeId  = Input::get('type');
        $exists  = Foundation::make('antares.customfields.model.view')
                ->query()
                ->where('group_id', $groupId)
                ->where('type_id', $typeId)
                ->where('name', $value)
                ->exists();
        if ($exists) {
            $this->setCustomMessages(['name-on-create' => trans('antares/customfields::validator.create.name-non-unique')]);
            $this->addFailure($attribute, 'name-on-create', []);
            return false;
        }


        return true;
    }
155096
private function setLink($name, $link)
    {
        if (! is_string($link) and ! is_object($link)) {
            throw new ValidationException(
                'Link attribute has to be an object or string, "' .
                gettype($link) . '" given.'
            );
        }

        if (is_string($link)) {
            $this->set($name, strval($link));

            return;
        }

        // Now $link can only be an object
        $this->set($name, $this->create('Link', $link));
    }
532733
final public function validateParameters(array $parameters)
    {
        $parameters = array_map(function ($rules) {
            if (is_bool($rules) and $rules === true) {
                return 'required';
            }

            return $rules;

        }, $parameters);

        $validator = Validator::make(Request::all(), $parameters);

        if ($validator->fails()) {
            throw new MissingParameterException(
                $validator->errors()->getMessages()
            );
        }

        return true;
    }
1152454
public function getIdAttribute($name, $attributes)
    {
        if (array_key_exists('id', $attributes)) {
            return $attributes['id'];
        }

        if (in_array($name, $this->labels)) {
            return $name;
        }
    }
1072206
public function open(String $name = NULL, Array $_attributes = [])
    {
        $this->clearValidationSessions();

        $this->setFormName($name, $_attributes);

        $this->isEnctypeAttribute($_attributes);
       
        $this->isWhereAttribute($name);
        
        $this->isQueryAttribute();

        $this->isPreventAttribute();
        
        $this->setMethodType($_attributes);
        
        $this->createFormElementByAttributes($_attributes, $return);

        $this->isDatabaseProcessWithName($name, $return);

        $this->isCSRFAttribute($return);

        $this->_unsetopen();

        $this->outputElement .= $return;

        return $this;
    }
555453
public function changeField($name, array $attributes)
    {
        //Argument 1 must be a string
        Argument::i()->test(1, 'string');
        
        $this->changeFields[$name] = $attributes;
        return $this;
    }
200302
public function add($name, $label = '', array $attributes = array(), array $rules = array())
	{
		if ($name instanceof Fieldset_Field)
		{
			if ($name->name == '' or $this->field($name->name) !== false)
			{
				throw new \RuntimeException('Fieldname empty or already exists in this Fieldset: "'.$name->name.'".');
			}

			$name->set_fieldset($this);
			$this->fields[$name->name] = $name;
			return $name;
		}
		elseif ($name instanceof Fieldset)
		{
			if (empty($name->name) or $this->field($name->name) !== false)
			{
				throw new \RuntimeException('Fieldset name empty or already exists in this Fieldset: "'.$name->name.'".');
			}

			$name->set_parent($this);
			$this->fields[$name->name] = $name;
			return $name;
		}

		if (empty($name) || (is_array($name) and empty($name['name'])))
		{
			throw new \InvalidArgumentException('Cannot create field without name.');
		}

		// Allow passing the whole config in an array, will overwrite other values if that's the case
		if (is_array($name))
		{
			$attributes = $name;
			$label = isset($name['label']) ? $name['label'] : '';
			$rules = isset($name['rules']) ? $name['rules'] : array();
			$name = $name['name'];
		}

		// Check if it exists already, if so: return and give notice
		if ($field = $this->field($name))
		{
			\Error::notice('Field with this name exists already in this fieldset: "'.$name.'".');
			return $field;
		}

		$this->fields[$name] = new \Fieldset_Field($name, $label, $attributes, $rules, $this);

		return $this->fields[$name];
	}
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);
    }
440721
public function addSelect($name, $attributes = array()) {
	
		$control = new FormControlSelect($name, $attributes);
		$this->addControl($control);
	
		return $control;
	
	}
887529
public function isValid(array $attributes, $rules = 'rules')
    {
        //validator
        $validator = $this->factory->make($attributes, static::${$rules});

        //passes validation
        if (!$validator->fails()) {
            return true;
        }

        //set errors
        $this->errors = $validator->getMessageBag();

        //return
        return false;
    }
1037573
private static function checkDataAttribute(array &$attributes, $name, array $supported, $default)
    {
        $attribute = $attributes[$name] ?? null;

        if ( ! is_null($attribute)) {
            $attribute = (is_string($attribute) && in_array($attribute, $supported))
                ? strtolower(trim($attribute))
                : $default;

            $attributes[$name] = $attribute;
        }
    }
88964
public function hasAttribute( $name )
    {
        return in_array( $name, array_keys( $this->attributes ) ) || isset( $this->dynamicAttributeFunctions[$name] );
    }
822949
protected function isValidAttribute($name)
    {
        $pattern = '~^' . self::ATTRIBUTE_REGEX . '$~i';
        $result = @preg_match($pattern, $name);
        return (bool)$result;
    }
1251824
private static function validateParams($name, $params, array $others) {
        if (is_array($params)) {
            foreach ($params + $others as $key => $value) {
                if ($key === '' || $value === null) {
                    unset($params[$key]);
                    continue;
                }
                $params[$key] = self::validateString("{$name}[$key]", $value);
            }
            return $params;
        }
        if (false === $params = filter_var($params)) {
            throw new InvalidArgumentException("The value of $name must be a 1-demensional array or query string.");
        }
        $tmp = $others;
        if ('' !== $params = trim($params)) {
            foreach (explode('&', $params) as $pair) {
                list($key, $value) = explode('=', $pair, 2) + array(1 => '');
                $tmp[urldecode($key)] = urldecode($value);
            }
        }
        return $tmp;
    }
373569
public function validateValidatorList($attribute, $value, $parameters)
    {
        $validators = Input::get('validators');
        if (!is_null($validators)) {
            foreach ($validators as $index => $id) {
                if (isset($value[$id]) && $value[$id] == '') {
                    $this->setCustomMessages(["validator_custom[{$id}]" => trans('antares/customfields::validator.create.validators-empty-fields')]);
                    $this->addFailure("validator_custom[{$id}]", "validator_custom[{$id}]", []);
                    break;
                }
            }
        }

        return true;
    }