min-arr-count:<minimum_value>

@param \MadeSimple\Validator\Validator $validator
@param array $data
@param string $pattern
@param string $rule
@param array  $parameters
420997
public static function minArrCount(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $min = $parameters[0];

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

            if (count($value) >= $min) {
                break;
            }

            $validator->addError($attribute, $rule, [':min' => $min]);
        }
    }
1086605
public static function is(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $is_a_func = sprintf('is_%s', $parameters[0]);
        if (!function_exists($is_a_func)) {
            return;
        }

        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            // As "is:<type>" is validating value type only ignore null
            if (null === $value) {
                continue;
            }
            if (call_user_func($is_a_func, $value)) {
                continue;
            }

            $validator->addError($attribute, $rule, [':type' => $parameters[0]]);
        }
    }
544223
protected function createValidator(array $data, array $rules)
    {
        /** @var Factory $factory */
        $factory   = app('validator');
        $validator = $factory->make($data, $rules);

        return $validator;
    }
36493
public function make($data, $rules)
    {
        $result = app('validator')->make($data, $rules);
        if ($result->fails()) {
            $this->errors = $result->messages()->toArray();
            return false;
        }
        $this->reset();
        return true;
    }
1030212
public function validateData(Request $request, array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        $validator = $this->getValidationFactory()->make($data, $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            $this->throwValidationException($request, $validator);
        }
    }
610649
protected function formatMessage($parameter, $ruleName, $ruleParameter, $message = null)
    {
        $message = $message ?: (isset($this->validateMessages[$ruleName]) ? $this->validateMessages[$ruleName] : $this->validateMessages['default']);
        $message = str_replace(':parameter', $parameter, $message);
        $method  = 'format'.ucfirst(Helper::camelCase($ruleName)).'Message';

        if (method_exists($this, $method)) {
            return $this->$method($ruleParameter, $message);
        }

        return $message;
    }
97328
public function requireCallback($value, $rule, $data) {
        $result = call_user_func_array([$this, $rule], [$value, $data]);

        if ($result) {
            return !empty($value) || '0' == $value;
        }

        return true;
    }
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
290809
public function validateConfig(array $rules, array $configData)
    {
        $validator = $this->createNew(Validator::class);
        
        if ($validator->isValid($rules, $configData) == false) {
            throw new DataValidationException('The config is invalid: ' . print_r($validator->getErrors(), 1));
        }
    }
376900
protected function _validateData($rule, $key, $data)
    {
        if (
            (is_callable($rule) && call_user_func_array($rule, [$key, $data, $this]))
            || @preg_match($rule, $data)
        ) {
            return true;
        }

        if ($rule instanceof Closure) {
            $reflection = new ReflectionFunction($rule);
            $rule       = $reflection->__toString();
        }

        $this->_errorsList[] = [
            'message'   => 'validation_mismatch',
            'key'       => $key,
            'data'      => $data,
            'rule'      => $rule,
        ];
        $this->_hasErrors = true;

        return false;
    }
135964
protected function lt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value < $val;
    }
1169667
public function rule($rule, $fields, ...$params)
    {
        if (\is_callable($rule)
            && !(\is_string($rule) && $this->hasValidator($rule))
        ) {
            $name = $this->getUniqueRuleName($fields);
            $message = $params[0] ?? null;
            $this->addInstanceRule($name, $rule, $message);
            $rule = $name;
        }

        $errors = $this->getRules();
        if (!isset($errors[$rule])) {
            $ruleMethod = 'validate' . \ucfirst($rule);
            if (!\method_exists($this, $ruleMethod)) {
                throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
            }
        }

        // Ensure rule has an accompanying message
        $messages = $this->getRuleMessages();
        $message = $messages[$rule] ?? self::ERROR_DEFAULT;

        // Ensure message contains field label
        if (\strpos($message, '{field}') === false) {
            $message = '{field} ' . $message;
        }

        $this->_validations[] = [
            'rule' => $rule,
            'fields' => (array) $fields,
            'params' => (array) $params,
            'message' => '{field} ' . $message,
            'skip' => self::SKIP_CONTINUE,
        ];

        return $this;
    }
598269
public function applyRules(array $rules = [], array $data = []): array
    {
        $data  = $data ?: $this->_data;
        $rules = $rules ?: $this->_rules;
        // save clean data
        $filtered = [];

        foreach ($rules as $rule) {
            if (!isset($rule[0], $rule[1])) {
                continue;
            }

            if (!$fields = $rule[0]) {
                continue;
            }

            $fields = \is_string($fields) ? Filters::explode($fields) : (array)$fields;

            foreach ($fields as $field) {
                if (!isset($data[$field])) {
                    $filtered[$field] = $rule['default'] ?? null;
                } else {
                    $filtered[$field] = $this->valueFiltering($data[$field], $rule[1]);
                }
            }
        }

        return $filtered;
    }
1305363
public function validate($data, $validators, $throw = true)
    {
        $validators = $this->getValidators($validators);
        foreach ($validators as $validator) {
            $validator = explode(':', $validator);

            $functionParams = [
                $data,
                array_splice($validator, 1),
                $throw
            ];

            if (!array_key_exists($validator[0], $this->validators)) {
                throw new ValidationException('Validator %s does not exist!', $validator[0]);
            }
            $res = $this->validators[$validator[0]]->validate(...$functionParams);

            // If validation failed and we are not throwing, return error message string
            if ($res !== true && !$throw) {
                return $res;
            }
        }

        return true;
    }
1264856
public function settingsValidate(Event $event, $data, Validator $validator)
    {
        if (isset($data['password_min_length'])) {
            $validator
                ->add('password_min_length', 'validNumber', [
                    'rule' => ['naturalNumber', false], // false: exclude zero
                    'message' => __d('user', 'Invalid password min-length.')
                ]);
        }

        $validator
            ->requirePresence('message_welcome_subject')
            ->notEmpty('message_welcome_subject', __d('user', 'This field cannot be empty.'))

            ->requirePresence('message_welcome_body')
            ->notEmpty('message_welcome_body', __d('user', 'This field cannot be empty.'))

            ->requirePresence('message_password_recovery_subject')
            ->notEmpty('message_password_recovery_body', __d('user', 'This field cannot be empty.'))

            ->requirePresence('message_cancel_request_subject')
            ->notEmpty('message_cancel_request_body', __d('user', 'This field cannot be empty.'));

        if ($data['message_activation']) {
            $validator
                ->requirePresence('message_activation_subject')
                ->notEmpty('message_activation_body', __d('user', 'This field cannot be empty.'));
        }

        if ($data['message_blocked']) {
            $validator
                ->requirePresence('message_blocked_subject')
                ->notEmpty('message_blocked_body', __d('user', 'This field cannot be empty.'));
        }

        if ($data['message_canceled']) {
            $validator
                ->requirePresence('message_canceled_subject')
                ->notEmpty('message_canceled_body', __d('user', 'This field cannot be empty.'));
        }
    }
721765
protected function validateIs($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'is' must have argument in validator list for parameter {$parameter}");
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = trim((string)$value);

        if ($value === '') {
            return null;
        }

        if ($value !== $args[0]) {
            return Message::getMessage(Message::IS, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        return null;
    }
417528
protected function validateEndsWith($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'endsWith' must have argument in validator list for parameter {$parameter}");
        }

        $endsWith = $args[0] ?? '';

        if (strlen($endsWith) == 0) {
            throw new ValidatorConfigException("Validator 'endsWith' have empty argument in validator list for parameter {$parameter}");
        }

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = trim((string)$value);

        if ($value === '') {
            return null;
        }

        if (!Util::endsWith($value, $endsWith)) {
            return Message::getMessage(Message::ENDS_WITH, [
            	'endsWith' => $endsWith,
                'param' => $parameter,
                'value' => $value
            ]);
        }

        return null;
    }