{@inheritdoc}

@param Validation $validation
@param string     $format
@param array      $keyTitles (optional)
@param array      $customMessages (optional)

@return mixed
969735
public function convert(Validation $validation, $format, array $keyTitles = [], array $customMessages = [])
    {

        if (!in_array($format, $this->supportedFormats)) {
            throw new UnsupportedParameterException(static::class . ' only supports MessageBag');
        }

        $messages = new MessageBag;

        if (!count($validation)) {
            return $messages;
        }

        foreach ($validation as $key=>$rules) {
            foreach ($rules as $ruleName=>$parameters) {
                $message = $this->getMessage($key, $ruleName, $rules, $keyTitles, $customMessages);
                $messages->add($key, $message);
            }
        }

        return $messages;

    }
494895
public function get_errors($key = null, string $format = ':message'): array
    {
        return $this->validation->get_errors($key, $format);
    }
238160
private function createValidator(array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->getValidatorFactory()->make($data, $rules, $messages, $customAttributes);
    }
425729
public static function validate($request, $rules, $messages=[])
    {
        $errors = [];
        $files = $request->getUploadedFiles();

        foreach ($rules as $field => $rule)
        {
            try
            {
                if ($rule instanceof v)
                {
                    // check if the field is for file
                    if (isset($files[$field]))
                    {
                        if (is_array($files[$field])) // multiple file
                        {
                            $files = $files[$field];
                            foreach ($files as $file_row)
                            {
                                if ($file_row instanceof UploadedFile)
                                {
                                    $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($file_row->file));
                                }
                            }
                        }
                        else // single file
                        {
                            if ($files[$field] instanceof UploadedFile)
                            {
                                $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($files[$field]->file));
                            }
                        }
                    }
                    else
                    {
                        $rule->setName(str_title(ucfirst($field)))->assert($request->getParam($field));
                    }
                }
                else
                {
                    \Log::error("Error: Rule must be Respect\Validation\Validator object");
                }
            } catch (NestedValidationException $e) {
                $translator = config('validation.translator');
                $e->setParam('translator', function($message) use($translator) {
                    $language = $translator['lang'];
                    $messages = $translator['messages'];

                    return isset($messages[$message]) ? $messages[$message][$language] : $message;
                });

                $e->findMessages($messages);
                $errors[$field] = $e->getMessages();
            }
        }
        Session::set('errors', $errors);
        return __CLASS__;
    }
1346568
public static function format($key, $value, $formats)
    {
        foreach ($formats as $pkey => $format) {
            $parts = explode(':', $format);
            if (sizeof($parts) === 1) {
                continue;
            }

            if ($pkey == $key) {
                $method = array_shift($parts);

                if (method_exists(get_class(), $method)) {
                    return self::$method($value, implode(':', $parts));
                }
                break;
            }
        }

        return $value;
    }
879260
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(isset($_FILES[$key])) {
            if(!\file_exists($_FILES[$key]['tmp_name'])) {
                return 'formvalidator_make_invalid_file';
            }
            
            $size = \getimagesize($_FILES[$key]['tmp_name']);
        } else {
            if(!$exists) {
                return false;
            }
            
            $size = @\getimagesizefromstring($value);
        }
        
        if(!$size) {
            return 'formvalidator_make_invalid_file';
        }
        
        $n = \explode(',', $options);
        foreach($n as $x) {
            $k = \explode('=', $x);
            switch($k[0]) {
                case 'min_width': // @codeCoverageIgnore
                    if($k[1] > $size[0]) {
                        return array('formvalidator_make_min_width', array('{0}' => $options));
                    }
                break;
                case 'min_height': // @codeCoverageIgnore
                    if($k[1] > $size[1]) {
                        return array('formvalidator_make_min_height', array('{0}' => $options));
                    }
                break;
                case 'width': // @codeCoverageIgnore
                    if($k[1] != $size[0]) {
                        return array('formvalidator_make_width', array('{0}' => $options));
                    }
                break;
                case 'height': // @codeCoverageIgnore
                    if($k[1] != $size[1]) {
                        return array('formvalidator_make_height', array('{0}' => $options));
                    }
                break;
                case 'max_width': // @codeCoverageIgnore
                    if($k[1] < $size[0]) {
                        return array('formvalidator_make_max_width', array('{0}' => $options));
                    }
                break;
                case 'max_height': // @codeCoverageIgnore
                    if($k[1] < $size[1]) {
                        return array('formvalidator_make_max_height', array('{0}' => $options));
                    }
                break;
                case 'ratio': // @codeCoverageIgnore
                    if(\mb_strpos($k[1], '/') !== false) {
                        $k[1] = \explode('/', $k[1]);
                        $k[1] = $k[1][0] / $k[1][1];
                    }
                    
                    if(\number_format(($size[0] / $size[1]), 1) != \number_format($k[1], 1)) {
                        return array('formvalidator_make_ratio', array('{0}' => $options));
                    }
                break;
            }
        }
        
        return true;
    }
1091187
public function validate(array $data, $rules = null, $custom = false)
    {
        if (!$custom) {
            $rules = $this->rules($rules);
        }

        return $this->validator->make($data, $rules);
    }
1020030
public function validate(Request $request, array $rules, array $messages = [])
    {
        foreach ($rules as $param => $options) {
            $value = $request->getParam($param);
            $this->data[$param] = $value;
            $isRule = $options instanceof V;

            try {
                if ($isRule) {
                    $options->assert($value);
                } else {
                    if (!isset($options['rules']) || !($options['rules'] instanceof V)) {
                        throw new InvalidArgumentException('Validation rules are missing');
                    }

                    $options['rules']->assert($value);
                }
            } catch (NestedValidationException $e) {
                $paramRules = $isRule ? $options->getRules() : $options['rules']->getRules();

                // Get the names of all rules used for this param
                $rulesNames = [];
                foreach ($paramRules as $rule) {
                    $rulesNames[] = lcfirst((new ReflectionClass($rule))->getShortName());
                }

                // If the 'message' key exists, set it as only message for this param
                if (!$isRule && isset($options['message']) && is_string($options['message'])) {
                    $this->errors[$param] = [$options['message']];
                    return $this;
                } else { // If the 'messages' key exists, override global messages
                    $params = [
                        $e->findMessages($rulesNames)
                    ];

                    // If default messages are defined
                    if (!empty($this->defaultMessages)) {
                        $params[] = $e->findMessages($this->defaultMessages);
                    }

                    // If global messages are defined
                    if (!empty($messages)) {
                        $params[] = $e->findMessages($messages);
                    }

                    // If individual messages are defined
                    if (!$isRule && isset($options['messages'])) {
                        $params[] = $e->findMessages($options['messages']);
                    }

                    $this->errors[$param] = array_values(array_filter(call_user_func_array('array_merge', $params)));
                }
            }
        }

        return $this;
    }
390739
function getValidationScript($format = null) {
        global $CFG;
        if (!empty($CFG->strictformsrequired)) {
            if (!empty($format) && $format == FORMAT_HTML) {
                return array('', "{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\s+/ig, '') == ''");
            } else {
                return array('', "{jsVar}.replace(/^\s+$/g, '') == ''");
            }
        } else {
            return array('', "{jsVar} == ''");
        }
    }
906252
public function validate(array $params, array $rules, array $messages = [])
    {
        $validator = app(Validator::class)->make($params, $rules, $messages);

        if ($validator->fails()) {
            throw new ValidationException(
                $validator, new JsonResponse($validator->errors()->getMessages(), 422)
            );
        }
    }
983205
protected function formatMessages($messages, $format, $type = '')
    {

        if ($format === self::Format_Array) {
            $result = $messages;
        } else {
            $result = array();
            foreach ($messages as $message) {
                if (is_array($message)) {
                    $messagePart = "{$message['code']}: ";
                    $messagePart .= $this->t($message['message']);
                    if ($message['codetag']) {
                        $messagePart .= " ({$message['codetag']})";
                    }
                    $message = $this->t($type) . ' ' . $messagePart;
                }
                if ($format === self::Format_FormattedText) {
                    $message = "* $message\n\n";
                } elseif ($format === self::Format_Html) {
                    $message = "<li>" . nl2br(htmlspecialchars($message, ENT_NOQUOTES)) . "</li>\n";
                }
                $result[] = $message;
            }
            if ($format === self::Format_FormattedText) {
                $result = implode('', $result);
            } elseif ($format === self::Format_Html) {
                $result = "<ul>\n" . implode('', $result) . "</ul>\n";
            }
        }
        return $result;
    }
1222872
protected function transform($messages, $format, $messageKey)
    {
        return collect((array) $messages)
            ->map(function ($message) use ($format, $messageKey) {
                // We will simply spin through the given messages and transform each one
                // replacing the :message place holder with the real message allowing
                // the messages to be easily formatted to each developer's desires.
                return str_replace([':message', ':key'], [$message, $messageKey], $format);
            })->all();
    }
385248
public static function validText(
        $msg = '',
        $options = [],
        $default = null,
        $noValidMessage = null,
        $attemptTimes = 3,
        $failCloseMessage = false
    ) {
        $prompter = new ValidatePrompter();

        $prompter->setOptions($options);

        static::prepareCallbackPrompter($prompter, $noValidMessage, $attemptTimes, $failCloseMessage);

        return $prompter->ask($msg, $default);
    }
405229
protected function validate($input, array &$messages)
    {
        if ($input === '') {
            return;
        }

        $validChars = [];

        foreach ($this->charRanges as $startChar => $endChar) {
            $validChars += array_fill_keys(range($startChar, $endChar), true);
        }

        foreach (str_split($input) as $char) {
            if (!isset($validChars[$char])) {
                $messages[] = new Message(self::MESSAGE, ['valid_chars' => $this->formatCharRanges($this->charRanges)]);
                return;
            }
        }
    }
388275
protected function extractCustomValidationShortName(array $rules)
    {
        $customRules = array_map(function ($rule) {
            $fullname = $this->getCustomRuleFullName($rule);

            if ($this->canHaveUsingCommand($fullname)) {
                $shortName = $this->getCustomRuleShortName($fullname);

                return $this->makeCustomRuleCall($shortName);
            }

            return $this->makeCustomRuleCall($fullname);

        }, $rules);

        return $customRules;
    }
812679
public function setFormat($format)
    {
        if (empty($format) || !is_string($format)) {

            throw new Zend_Validate_Exception("A postcode-format string has to be given for validation");
        }

        if ($format[0] !== '/') {
            $format = '/^' . $format;
        }

        if ($format[strlen($format) - 1] !== '/') {
            $format .= '$/';
        }

        $this->_format = $format;
        return $this;
    }
869370
public function validate(RequestModel $request, array $rules, array $messages = [], array $customAttributes = [])
    {
        if ($request instanceof RequestModelCollection) {
            $request->map(function (RequestModel $requestModel) use ($rules) {
                $this->validate($requestModel, $rules);
            });
            return;
        }

        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            $this->throwValidationException($request->request(), $validator);
        }
    }