adds a error message

@param string $key
@param string $rule
@param string $specialRule
@param array $datas
184554
protected function addMessage($key, $rule, $specialRule, array $datas = [])
    {
        $specialMessages = $this->getMessageReposity();
        $defaultMessages = $this->defaultErrorMessages;

        if (count($datas) === 0) {
            $datas = [$key];
        }

        if (isset($specialMessages[$specialRule])) {
            $selectedMessage = $specialMessages[$specialRule];
        } else {
            $selectedMessage = $defaultMessages[$rule];
        }

        array_unshift($datas, $selectedMessage);
        $this->failedMessages[] = call_user_func_array('sprintf', $datas);
    }
940794
private function validateData($rules, $data) {
		$errors = [];
		foreach ($rules as $field => $rule) {
			$valid = $this->validateField($field, $data, $rule);
			if ($valid !== true) {
				$errors[ $field ] = $valid;
			}
		}
		if (!empty($errors)) {
			throw new ValidateException($errors);
		}

		return true;
	}
703576
protected function _validateDataKey($key, $data)
    {
        $dataOkFlag = true;

        if (!$this->_validationOn) {
            return $dataOkFlag;
        }

        foreach ($this->_validationRules as $ruleKey => $ruleValue) {
            if (!preg_match($ruleKey, $key)) {
                continue;
            }

            $bool = $this->_validateData($ruleValue, $key, $data);
            if (!$bool) {
                $dataOkFlag = false;
            }
        }

        return $dataOkFlag;
    }
995786
public function addRule($rule, $method = null, $params = [], $message = null)
    {

        // construction des paramètres
        array_unshift($params, $rule, $method);

        call_user_func_array([$this->getValidator(), 'addRule'], $params);

        if (!is_null($message)) {
            if(is_array($message)){
                foreach($message as $rule => $message){
                    $this->getValidator()->addMessage($rule, $message);
                }
            }else{
                $this->getValidator()->addMessage($rule, $message);
            }
        }

        return $this;
    }
152158
protected function hasRule(array $keyRules, $ruleNames)
    {

        $ruleNames = (array)$ruleNames;

        foreach ($keyRules as $ruleName=>$parameters) {
            if (in_array($ruleName, $ruleNames)) {
                return true;
            }
        }

        return false;
    }
804020
public function addRule(string $key, string $rule) : ValidatorInterface
    {
        $this->rules[$key] = $rule;

        return $this;
    }
302407
private function prepareRecord(array $data, array $rules, array $messages)
    {
        // Reset error bag
        $this->errors = new MessageBag;

        // Capture data
        $this->setDataset($data);
        $this->setRuleset($rules);
        $this->setMessageset($messages);

        // Fill model
        $this->fillModel();
    }
127794
private function validate($rules, $blockData)
    {
        /**
         * Make sure that every required param exists in data block
         */
        foreach ($rules as $key => $value) {
            if (($key != BlockHandler::DEFAULT_ARRAY_KEY) && (isset($value['required']) ? $value['required'] : true)) {
                if (!isset($blockData[$key])) {
                    throw new EditorJSException("Not found required param `$key`");
                }
            }
        }

        /**
         * Check if there is not extra params (not mentioned in configuration rule)
         */
        foreach ($blockData as $key => $value) {
            if (!is_integer($key) && !isset($rules[$key])) {
                throw new EditorJSException("Found extra param `$key`");
            }
        }

        /**
         * Validate every key in data block
         */
        foreach ($blockData as $key => $value) {
            /**
             * PHP Array has integer keys
             */
            if (is_integer($key)) {
                $key = BlockHandler::DEFAULT_ARRAY_KEY;
            }

            $rule = $rules[$key];

            $rule = $this->expandToolSettings($rule);

            $elementType = $rule['type'];

            /**
             * Process canBeOnly rule
             */
            if (isset($rule['canBeOnly'])) {
                if (!in_array($value, $rule['canBeOnly'])) {
                    throw new EditorJSException("Option '$key' with value `$value` has invalid value. Check canBeOnly param.");
                }

                // Do not perform additional elements validation in any case
                continue;
            }

            /**
             * Validate element types
             */
            switch ($elementType) {
                case 'string':
                    if (!is_string($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be string");
                    }
                    break;

                case 'integer':
                case 'int':
                    if (!is_integer($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be integer");
                    }
                    break;

                case 'array':
                    $this->validate($rule['data'], $value);
                    break;

                case 'boolean':
                case 'bool':
                    if (!is_bool($value)) {
                        throw new EditorJSException("Option '$key' with value `$value` must be boolean");
                    }
                    break;

                default:
                    throw new EditorJSException("Unhandled type `$elementType`");
            }
        }

        return true;
    }
199138
public static function make(array $data, array $rules, array $userMessages = [])
    {
        self::$validatorFacade = new ValidatorFacade($userMessages);

        $data = self::prepareData($data);
        $rules = self::prepareRules($rules);

        foreach ($rules as $fieldName => $fieldRules) {
            $fieldName = trim($fieldName);
            $fieldRules = trim($fieldRules);

            if (!$fieldRules) {
                //no rules
                continue;
            }

            $groupedRules = explode('|', $fieldRules);

            foreach ($groupedRules as $concreteRule) {
                $ruleNameParam = explode(':', $concreteRule);
                $ruleName = $ruleNameParam[0];

                //for date/time validators
                if (count($ruleNameParam) >= 2) {
                    $ruleValue = implode(':', array_slice($ruleNameParam, 1));

                    //for other params
                } else {
                    $ruleValue = isset($ruleNameParam[1]) ? $ruleNameParam[1] : '';
                }

                self::$config[BaseRule::CONFIG_DATA] = $data;
                self::$config[BaseRule::CONFIG_FIELD_RULES] = $fieldRules;

                $ruleInstance = RulesFactory::createRule($ruleName, self::$config, [
                    $fieldName,                                        // The field name
                    isset($data[$fieldName]) ? $data[$fieldName] : '', // The provided value
                    $ruleValue,                                        // The rule's value
                ]);

                if (!$ruleInstance->isValid()) {
                    self::$validatorFacade->chooseErrorMessage($ruleInstance);
                }
            }
        }

        return self::$validatorFacade;
    }
684995
public static function strLen(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $length = $parameters[0];

        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if (strlen($value) === (int) $length) {
                continue;
            }

            $validator->addError($attribute, $rule, [':length' => $length]);
        }
    }
1103918
protected function addRule($key, $rules)
    {
        if ($this->shouldSanitize($key)) {
            throw new InvalidArgumentException(sprintf(
                'Sanitation rules are already defined for field [%s]', $key
            ));
        }

        $this->rules[$key] = $this->buildRules($rules);
    }
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;
        }
    }
684023
public static function in(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value) {
                continue;
            }
            if (in_array($value, $parameters)) {
                continue;
            }

            $validator->addError($attribute, $rule, ['%values' => implode(', ', $parameters)]);
        }
    }
651338
protected function validate($data, $rules)
    {
        $data = array_filter($data);

        $validator = $this->validator->make($data, $rules);

        if ($validator->fails()) {
            throw new PagSeguroException($validator->messages()->first(), 1003);
        }
    }
509755
private function tryValidateData(
        array $data,
        array $rules,
        Closure $validationFailed,
        array $messages = [],
        array $customAttributes = []
    ) {
        $validator = $this->createValidator($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            call_user_func($validationFailed, $validator->errors()->getMessages());
        }
    }
61645
protected function makeValidationRuleDataFromSpecialArraySyntax(array $rules, $key)
    {
        $data = new ValidationRuleData(
            array_get($rules, 'rules', []),
            array_get($rules, 'key', is_numeric($key) ? null : $key)
        );

        if (array_has($rules, 'translated')) {
            $data->setIsTranslated((bool) $rules['translated']);
        }

        if (array_has($rules, 'locale_index')) {

            // @codeCoverageIgnoreStart
            if ((int) $rules['locale_index'] < 1) {
                throw new UnexpectedValueException(
                    "Locale index for configured validation data cannot be less than 1 (key/index: {$key})"
                );
            }
            // @codeCoverageIgnoreEnd

            $data->setLocaleIndex((int) $rules['locale_index']);
        }

        return $data;
    }
564388
public static function validate($data, $rules)
	{
		$errors = array();

		foreach ($data as $k => $v)
		{
			if (array_key_exists($k, $rules))
			{
				// (Re)set rule variable
				$rule = null;

				if (is_callable($rules[$k]))
				{
					if ($error = call_user_func_array($rules[$k], [$data]))
					{
						$errors[] = $error;
					}
				}
				else if (strpos($rules[$k], '|'))
				{
					$rule = explode('|', $rules[$k]);
				}
				else
				{
					$rule = array($rules[$k]);
				}

				if (isset($rule))
				{
					foreach ($rule as $r)
					{
						if (method_exists(__CLASS__, $r))
						{
							if ($error = self::$r($k, $v))
							{
								$errors[] = $error;
							}
						}
					}
				}
			}
		}

		return (count($errors) > 0) ? $errors : true;
	}