Parses a given rule with the given input.

@param string $rule  - The rule being parsed
@param array  $input - Form input array
@param string $key   - Validation option
972708
private function parseRule($rule, $input, $key)
    {
        $ruleExp = explode(':', $rule);
        if (count($ruleExp) > 1) {
            switch ($ruleExp[0]) {
                case 'match':
                $this->_errors[$key][] = $this->_parser->match($input, $key, $ruleExp[1], $this->_lang['match']);
                break;
                case 'min':
                $this->_errors[$key][] = $this->_parser->min($input, $key, $ruleExp[1], $this->_lang['min']);
                break;
                case 'max':
                $this->_errors[$key][] = $this->_parser->max($input, $key, $ruleExp[1], $this->_lang['max']);
                break;
                case 'from':
                $this->_errors[$key][] = $this->_parser->from($input, $key, $rule, $this->_lang['from']);
                break;
            }
        } else {
            switch ($rule) {
                case 'required':
                $this->_errors[$key][] = $this->_parser->required($input, $key, $this->_lang['required']);
                break;
                case 'email':
                $this->_errors[$key][] = $this->_parser->email($input, $key, $this->_lang['email']);
                break;
                case 'url':
                $this->_errors[$key][] = $this->_parser->url($input, $key, $this->_lang['url']);
                break;
            }
        }
    }
1247451
public function addLexerRule($rulename, $rule)
	{
		$this->rules[$rulename] = [];
		$this->rules[$rulename][] = $rule; 
	}
941958
protected function onInvalidEventAttributeValidate($key, $check = [], $rule = NULL)
    {
        $this->validate[] = $rule ?: $key;

        return $this->required()->onInvalidEventCustomValidity($key, $check);
    }
1231802
protected function isOneVoidValue($key, $rule = 'required_with')
    {
        $fields  = $this->getParamField($this->rules[ $key ], $rule);
        $require = new Rules\Required;

        foreach ($fields as $field) {
            if (!isset($this->inputs[ $field ])) {
                throw new \InvalidArgumentException(htmlspecialchars(
                    "The provided $field field does not exist."
                ));
            }
            $require->execute('required', $field, $this->inputs[ $field ], false, true);
            if ($require->hasErrors()) {
                return true;
            }
        }

        return false;
    }
1099345
protected function runAlpha($key, $datas, $rule)
    {
        $data = $datas[$key];

        if (!preg_match("([A-Z])", $data)) {
            $this->fails[] = $messageKey = "alpha.$key";

            $this->addMessage($key, $rule, $messageKey);
        }
    }
1082439
static function addRule(\CharlotteDunois\Validation\RuleInterface $rule) {
        if(static::$rulesets === null) {
            static::initRules();
        }
        
        $class = \get_class($rule);
        $arrname = \explode('\\', $class);
        $name = \array_pop($arrname);
        
        $rname = \str_replace('rule', '', \strtolower($name));
        static::$rulesets[$rname] = $rule;
        
        if(\stripos($name, 'rule') !== false) {
            static::$typeRules[] = $rname;
        }
    }
774126
protected function converterRules($rule, $keys = null) {
        if (is_integer($keys) && is_array($rule)) {
            $keys = array_shift($rule);
        }
        $rules = $this->converterRule($rule);
        $rules['keys'] = $keys;
        return $rules;
    }
981338
protected function updateRuleProperty($rule, $key, $value)
    {
        if (preg_match('/^[^.]+(\.[^.]+){3}$/', $rule)) {
            $this->current[$rule][$key] = $value;
            $this->commit();
        } else {
            throw new InvalidArgumentException('Invalid rule name!');
        }
    }
720890
public function collectRule(Rule $rule): void
    {
        $this->data['rule'] = [
            'id' => $rule->getId(),
        ];

        foreach ($rule->getTargets() as $target) {
            $this->data['rule']['targets'][] = [
                'type' => $target->getTargetType()::getType(),
                'value' => $this->formatVar($target->getValue()),
            ];
        }

        foreach ($rule->getConditions() as $condition) {
            $this->data['rule']['conditions'][] = [
                'type' => $condition->getConditionType()::getType(),
                'value' => $this->formatVar($condition->getValue()),
            ];
        }
    }
493678
private function validateRulesHasPlaceHolder($key, $rule, $isValid)
    {
        $string = string_split($rule, ':');

        if (!string_has($string[1], ',')) {
            return $this->doValidateData($string[0], $string[1], $isValid, $key);
        }

        return $this->doValidateData($string[0], $key, $isValid, $string[1]);
    }
134441
protected function validate($attribute, $rule)
	{
		list($rule, $parameters) = $this->parseRule($rule);

		if ($rule == '') return;

		// We will get the value for the given attribute from the array of data and then
		// verify that the attribute is indeed validatable. Unless the rule implies
		// that the attribute is required, rules are not run for missing values.
		$value = $this->getValue($attribute);

		$validatable = $this->isValidatable($rule, $attribute, $value);

		$method = "validate{$rule}";

		if ($validatable && ! $this->$method($attribute, $value, $parameters, $this))
		{
			$this->addFailure($attribute, $rule, $parameters);
		}
	}
34710
public function addRule(ValidatorRule $rule, $field, $flags = 0x00000) {
    $key = $this->getKey($field);
    $this->rules[$key][] = $rule;
    
    if ($rule instanceof FieldValidatorRule) {
      $rule->setField($field);
    }
    
    if ($flags & self::OPTIONAL) {
      $this->setOptional($field);
    }
  }
573887
private function doValidateData($rule, $key, $isValid, $other = '')
    {
        $method = Inflector::camelize($rule);

        if (!is_callable([$this, $method])) {
            throw new \Exception('Undefined method '.__CLASS__.' '.$method.' called.');
        }

        if ($isValid === false) {
            $this->setErrors($key.self::ERROR, Inflector::camelize((str_replace('_', ' ', $key))));
        }

        if (!isset($this->param[$key])) {
            throw new ValidatorException(sprintf('Key %s doesn\'t exists in $_POST array ', $key));
        }

        return (!empty($other)) ? $this->{$method}($key, $other) : $this->{$method}($key);
    }
464362
public function removeRules($keys, $ruleset = null)
    {
        $keys = is_array($keys) ? $keys : func_get_args();
        $rules = $ruleset ? $this->getRuleset($ruleset) : $this->getRules();
        array_forget($rules, $keys);
        if ($ruleset) {
            $this->setRuleset($rules, $ruleset);
        } else {
            $this->setRules($rules);
        }
    }
1124625
public function getMessage($key, $rule, $message = null) {
        $label = isset($this->labels[$key]) ? $this->labels[$key] : $key;
        if (!is_null($message)) {
            return str_replace(':attribute', $label, $message);
        }
        if (isset($this->messages[$key.'.'.$rule])) {
            return $this->messages[$key.'.'.$rule];
        }
        return str_replace(':attribute', $label, $this->messages[$rule]);
    }
664076
public function validate($rule = null)
    {
        if (is_null($rule)) {
            throw $this->exception('Incorrect usage of field validation');
        }

        if (is_string($rule)) {
            // If string is passed, prefix with the field name
            $rule = $this->short_name.'|'.$rule;
        } elseif (is_array($rule)) {
            // if array is passed, prepend with the rule
            array_unshift($rule, $this->short_name);
            $rule = array($rule);
        } elseif (is_callable($rule)) {
            // callable or something else is passed. Wrap into array.
            $rule = array(array($this->short_name, $rule));
        }

        $this->form->validate($rule);

        return $this;
    }
596945
public function parse($value, $rule) {
        $rs = strval($this->filterByStrLen(strval($value), $rule));

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

        return $rs;
    }