@param array $data
@param string $field_value
@param array $field_rules
@param array $messages

@return array|bool
518165
public static function validateFiled(array $data, string $field_value, array $field_rules, array $messages = [])
    {
        $errors = [];

        foreach ($field_rules as $check => $check_value) {

            switch ($check) {

                case 'required':
                    if (!$field_value) {
                        $errors[$check] = isset($messages['required']) ? w($messages['required']) : self::$messages['required'];
                    }

                    break;

                case 'min_length':

                    if (mb_strlen($field_value) < $check_value) {
                        $errors[$check] = sprintf(isset($messages['min_length']) ? w($messages['min_length']) : self::$messages['min_length'], $check_value);
                    }

                    break;

                case 'max_length':

                    if (mb_strlen($field_value) > $check_value) {
                        $errors[$check] = sprintf(isset($messages['max_length']) ? w($messages['max_length']) : self::$messages['max_length'], $check_value);
                    }

                    break;

                case 'min':

                    if ($field_value < $check_value) {
                        $errors[$check] = sprintf(isset($messages['min']) ? w($messages['min']) : self::$messages['min'], $check_value);
                    }

                    break;

                case 'max':

                    if ($field_value > $check_value) {
                        $errors[$check] = sprintf(isset($messages['max']) ? w($messages['max']) : self::$messages['max'], $check_value);
                    }

                    break;

                case 'pattern':

                    if (!preg_match($check_value, $field_value)) {
                        $errors[$check] = $check_value;
                    }

                    break;

                case 'min_checkboxes_checked':

                    break;

                case 'max_checkboxes_checked':

                    break;

                case 'equal_to_field':

                    if (!isset($data[$check_value]) || $field_value != $data[$check_value]) {
                        $errors[$check] = sprintf(isset($messages['max']) ? w($messages['max']) : self::$messages['max'], $check_value);
                    }

                    break;

                // Is used for invisible fields, substituting captcha: if filled, it is invalid
                case 'empty':

                    if (!empty($field_value)) {
                        $errors[$check] = isset($messages['empty']) ? w($messages['empty']) : self::$messages['empty'];
                    }

                    break;

                case 'type':

                    switch ($check_value) {

                        case 'email':

                            if (!Verify::email($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['email'];
                            }

                            break;

                        case 'number':

                            if (!is_numeric($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['number'];
                            }

                            break;

                        case 'integer':

                            if (!\is_numeric($field_value) || !filter_var($field_value, FILTER_VALIDATE_INT)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['integer'];
                            }

                            break;

                        case 'digits':

                            if (!ctype_digit($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['digits'];
                            }

                            break;

                        case 'alphanum':

                            if (!ctype_alnum($field_value)) {
                                $errors[$check] = isset($messages['type']) ? w($messages['type']) : self::$messages['aphanum'];
                            }

                            break;

                        case 'url':

                            if (!filter_var($field_value, FILTER_VALIDATE_URL)) {
                                $errors[$check] = isset($messages['url']) ? w($messages['url']) : self::$messages['url'];
                            }

                            break;
                    }

                    break;
            }
        }

        return empty($errors) ? true : $errors;
    }
1290752
public function validate(array $data, array $rules, array $messages = [])
	{
		// Build the validator.
		$validator = $this->validationFactory->make($data, $rules, $messages);

		// Return the errors, if any.
		if($validator->fails())
		{
			return new Payload($validator->messages(), 'invalid');
		}

		return new Payload($data, 'valid');
	}
942427
protected static function validateCriteria(array $data, array $fields): array
    {
        foreach (array_keys($data) as $key) {
            if (in_array($key, $fields)) {
                continue;
            }
            unset($data[$key]);
        }

        return $data;
    }
455625
public function says($messages, $attributes = [], $lead_ids = null)
    {
        $messages = $this->model->parse($messages);

        if ( ! is_null($lead_ids)) {
            $lead_ids = (array) $lead_ids;
            $leads = Lead::withTrashed()->whereIn('user_id', $lead_ids)->get();

            if (empty($leads) || $leads === null) {
                return;
            }

            $leads->each(function ($lead) use ($messages, $attributes) {
                $this->request->sendMessages($messages, $attributes, $lead);
            });
        } else {
            $this->request->sendMessages($messages, $attributes, $lead_ids);
        }

        return $this;
    }
1121966
private function SetObjData($_table, $_fields, $_data)
    {
        $this->table = $_table;
        $this->fields = $_fields;
        $this->data[] = array();

        if (isset($_data[0]) and is_array($_data[0])) {
            for ($i=0; $i<count($_data); $i++) {
                foreach ($this->fields as $field) {
                    if (isset($_data[$i][$field]) and !$this->IsFieldLocked($field)) {
                        $this->data[$i][$field] = $this->Escape($_data[$i][$field]);
                    }
                }
            }
        } else {
            foreach ($this->fields as $field) {
                if (isset($_data[$field]) and !$this->IsFieldLocked($field)) {
                    $this->data[0][$field] = $this->Escape($_data[$field]);
                }
            }
        }
    }
992804
public function filterInsertValues($data, $fields)
	{
		$insertValues = array();
		$field_keys = array_flip($fields);
		foreach ($data as $key => $values) {
			$filteredValues = array_intersect_key($values, $field_keys);
			$emptyFields = array_fill_keys($fields, null);
			$filledValues = array_values(array_merge($emptyFields, $filteredValues));
			$insertValues = array_merge($insertValues, $filledValues);
		}
		return $insertValues;
	}
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;
	}
1257729
public function validate($validationRules = [], $messages = [])
    {
        $fieldRules = $this->formHelper->mergeFieldsRules($this->fields);
        $rules = array_merge($fieldRules->getRules(), $validationRules);
        $messages = array_merge($fieldRules->getMessages(), $messages);

        $this->validator = $this->validatorFactory->make($this->getRequest()->all(), $rules, $messages);
        $this->validator->setAttributeNames($fieldRules->getAttributes());

        $this->eventDispatcher->dispatch(new BeforeFormValidation($this, $this->validator));

        return $this->validator;
    }
31488
public function check(array $data, array $messages = array())
    {

        // Merge the given messages with the set messages.
        $messages = array_merge($this->_messages, $messages);

        // Check the CSRF token if we have a session object
        if ($this->_session) {

            if (!isset($data['_token']) || $data['_token'] !== $this->_session->getToken()) {

                $this->_errors[] = $messages['csrf'];
                return false;

            }

        }

        // Loop all the set rules and validate
        foreach ($this->_rules as $key => $rules)
        {
            // If the rules are a string, break it apart
            if (is_string($rules))
                $rules = explode('|', $rules);

            // Get the data for the rule
            $input = isset($data[$key]) ? $data[$key] : null;

            // Get the type of the input
            $inputType = $this->getInputType($input);

            // Create a key for messages
            $m_key = str_replace(array('_', '-'), ' ', $key);

            // Loop through each rule and validate
            foreach($rules as $rule) {

                // Turn the rule into an array and explode if it has parameters
                $rule = strpos($rule, ':') !== false ? explode(':', $rule) : array($rule);

                // If the rule is "required", it's a built in rule
                if ($rule[0] == 'required') {

                    if (!$input || empty($input)) {

                        if (isset($messages['required.'.$key])) {
                            $message = $messages['required.'.$key];
                        } else {
                            $message = str_replace(':key', $m_key, $messages['required']);
                        }

                        $this->_errors[] = $message;

                        break;

                    }

                    continue;

                }

                // If it's not a required field we have been given null, skip it
                if (!$input || empty($input))
                    break;

                // Throw an error if we don't have a handler for the rule
                if (!isset(static::$_handlers[$rule[0]]))
                    continue;
                //throw new \Exception('m\Validator: "'.$rule[0].'" is not a valid rule.  No matching handler exists.');

                // Handle lazy loaded handlers
                if (!is_object(static::$_handlers[$rule[0]])) {
                    $handlerName = static::$_handlers[$rule[0]];
                    $handler = new $handlerName();
                    static::$_handlers[$rule[0]] = $handler;
                } else {
                    $handler = static::$_handlers[$rule[0]];
                }

                // If there are parameters, turn them into an array
                $params = (isset($rule[1])) ? explode(',', $rule[1]) : array();

                // Add the input field to the front of the params array
                array_unshift($params, $input);

                // Call the handler and pass it the parameters
                $result = call_user_func_array(array($handler, 'check'.ucfirst($inputType)), $params);

                // If the check failed, log an error and stop validating this field
                if ($result === false) {

                    // Shorthand message keys
                    $ruleFieldName      = $rule[0].'.'.$key;
                    $ruleTypeName       = $rule[0].'.'.$inputType;

                    // Determine which message is available to send
                    if (isset($messages[$ruleFieldName])) {
                        $message = $messages[$ruleFieldName];
                    } elseif (isset($messages[$ruleTypeName])) {
                        $message = $messages[$ruleTypeName];
                    } elseif (isset($messages[$rule[0]])) {
                        $message = $messages[$rule[0]];
                    } else {
                        $message = 'The :key field failed to validate.';
                    }

                    array_shift($params);

                    // Format and log the message
                    $this->_errors[] = $handler->formatMessage($message, $m_key, $params);

                    // Onto the next field
                    break;
                }
            }
        }

        // If we have errors, we failed...
        return count($this->_errors) > 0 ? false : true;
    }
278215
public function run(array $data, $checkFields = false)
    {
        $data = $this->filter($data, $this->filterRules());

        $this->validate(
            $data, $this->validationRules()
        );

        if ($checkFields === true) {
            $this->checkFields($data);
        }

        return $data;
    }
936826
public static function make(array $data, array $rules)
    {
        self::$validator = new V([]);
        self::$validator->labels($data);

        foreach ($rules as $rule => $columns) {
            if (is_string($columns)) {
                $columns = self::separte($columns);
            } else {
                $columns = $columns;
            }

            $value = self::getValue($rule);

            self::$validator->rule($value['rule'], $columns, $value['value']);
        }

        return new ValidationResult(self::$validator);
    }
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();
    }
334849
public function error($message, $data=null){
        is_object($data) && $data = (array)$data;
        $return = ['success' => false, 'message' => $message, 'data'=>$data];
        return $return;
    }
1290979
public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
    {
        // Adding the keys `value` and `extension` to the messages, only if it is missing.
        $addValueToArray = function (array &$a) {
            foreach ($a as $k => $v) {
                if (false === isset($v['value'])) {
                    $a[$k]['value'] = '';
                }
                if (false === isset($v['extension'])) {
                    $a[$k]['extension'] = '';
                }
            }

            return $a;
        };

        $messagesArray = [];
        foreach ($messages as $key => $message) {
            if ($message instanceof FormzMessage) {
                $message = $message->toArray();
            }

            $messagesArray[$key] = $message;
        }

        $addValueToArray($messagesArray);
        $addValueToArray($supportedMessages);

        $messagesResult = $supportedMessages;

        ArrayUtility::mergeRecursiveWithOverrule(
            $messagesResult,
            $messagesArray,
            (bool)$canCreateNewMessages
        );

        return $messagesResult;
    }
1129406
public function getUpdateErrors(array $data, array &$errors = [], $fieldset = null)
    {
        $schema = $this->schema;

        if (!is_null($fieldset)) {
            $schema = $fieldset;
        }

        $fields = $schema->getFields();
        $table = $schema->getName();
        $primary = $schema->getPrimaryFieldName();

        if ((!isset($data[$primary]) || !is_numeric($data[$primary])) && !is_null($primary)) {
            $errors[$primary] = 'Invalid ID';
        }

        foreach ($fields as $name => $field) {
            if ($field['field']['type'] === 'fieldset') {
                if (!isset($data[$name])) {
                    continue;
                }

                if (!isset($errors[$name])) {
                    $errors[$name] = [];
                }

                if (isset($field['field']['attributes']['data-multiple'])
                    && !$field['field']['attributes']['data-multiple']
                ) {
                    $errors[$name] = $this->getUpdateErrors(
                        $data[$name],
                        $errors[$name],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name])) {
                        unset($errors[$name]);
                    }

                    continue;
                }

                foreach($data[$name] as $index => $row) {
                    if (!isset($errors[$name][$index])) {
                        $errors[$name][$index] = [];
                    }

                    $errors[$name][$index] = $this->getUpdateErrors(
                        $row,
                        $errors[$name][$index],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name][$index])) {
                        unset($errors[$name][$index]);
                    }
                }

                if (empty($errors[$name])) {
                    unset($errors[$name]);
                }

                continue;
            }

            if (!isset($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                if ($validation['method'] === 'required'
                    && array_key_exists($name, $data)
                    && empty($data[$name])
                ) {
                    $errors[$name] = $validation['message'];
                }
            }
        }

        return $this->getOptionalErrors($data, $errors, $fieldset);
    }
1259040
public function validateDataWithRules(array $data, array $validateRules, array $validateMessages = [], array $parametricConverter = [])
    {
        foreach ($validateRules as $key => $rules) {
            $value = array_key_exists($key, $data) ? $data[$key] : null;

            if (array_key_exists('nullable', $rules) && $rules['nullable'] && is_null($value)) {
                continue;
            }

            unset($rules['nullable']);

            $defaultParametricConverter = (method_exists($this, 'getParametricConverter') && is_array($this->getParametricConverter())) ? $this->getParametricConverter() : [];
            $parametricConverter = array_merge($defaultParametricConverter, $parametricConverter);
            $parameter = (array_key_exists($key, $parametricConverter)) ? $parametricConverter[$key] : $key;

            foreach ($rules as $ruleName => $ruleParameter) {
                if ($ruleName === 'callback') {
                    if (!is_callable($ruleParameter)) {
                        throw new BadMethodCallException('The reference of rule named `callback` must be a valid callable. You provided ' . $this->getValueDescription($ruleParameter) . '.');
                    }

                    call_user_func($ruleParameter, $value, InvalidRequestException::class);
                } else {
                    $method = 'check'.ucfirst(Helper::camelCase($ruleName));

                    if (!method_exists($this, $method)) {
                        throw new BadMethodCallException('Call to undefined the ' .get_class($this). '::' .$method. '() validator that associated with the `' .$ruleName. '` rule');
                    }

                    if (!$this->$method($value, $ruleParameter)) {
                        $message = isset($validateMessages[$key][$ruleName]) ? $validateMessages[$key][$ruleName] : null;

                        throw new InvalidRequestException($this->formatMessage($parameter, $ruleName, $ruleParameter, $message));
                    }
                }
            }
        }
    }
1235484
static public function formatValue($field, $field_value=null)
    {
        $methods = [];
        if (isset($field['data_format']) && $field['data_format']) {
            $methods[] = $field['data_format'];
        }
        $methods[] = $field['field_name'];
        if (isset($field['base_type']) && $field['base_type']) {
            $methods[] = $field['base_type'];
        }
        $methods[] = $field['data_type'];
        
        foreach ($methods as $m) {
            if (method_exists(get_called_class(), $m)) {
                return static::$m($field_value);
            }
        }
        
        $data_type = strtolower($field['data_type']);
        if (preg_match('/int/', $data_type)) {
            $field_value = intval($field_value);
        } else {
            $field_value = static::output($field_value);
        }
        
        return $field_value;
    }