Validate if given value is hexadecimal number or not

@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules

@return null|string
@throws ValidatorConfigException
@example 'param' => 'hex'
763293
protected function validateHex($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        //$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[0] == '-') {
            $value = substr($value, 1);
        }

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

        return null;
    }
1265242
protected function _validate_length($value, $parameters)
    {
        $length = $this->_strlen($value);
        if (count($parameters) === 1) {
            $parameters = explode('-', $parameters[0]);
        }
        return $length >= $parameters[0] && $length <= $parameters[1] ? $value : null;
    }
1233263
public static function validateStrEqI($value, $equalsValue, $reason = null, $alias = 'Parameter')
    {
        if (is_string($value)) {
            if (strcasecmp($value, $equalsValue) === 0)
                return $value;
            $isTypeError = false;
        } else
            $isTypeError = true;

        if ($reason !== null)
            throw new ValidationException($reason);

        if ($isTypeError) {
            $error = self::getErrorTemplate('Str');
            $error = str_replace('{{param}}', $alias, $error);
        } else {
            $error = self::getErrorTemplate('StrEqI');
            $error = str_replace('{{param}}', $alias, $error);
            $error = str_replace('{{value}}', $equalsValue, $error);
        }
        throw new ValidationException($error);
    }
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]);
        }
    }
597733
public function validate($attribute, $rules, $value)
    {
        if (is_int($value)) {
            $value = (string)$value;
        } elseif (is_bool($value)) {
            $value = $value ? '1' : '0';
        } elseif ($value === null) {
            $value = '';
        }

        foreach ($rules as $k => $v) {
            if (is_int($k)) {
                $value = $this->_validate($attribute, $v, [], $value);
            } else {
                $value = $this->_validate($attribute, $k, is_array($v) ? $v : explode('-', $v), $value);
            }
        }

        return $value;
    }
984543
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $groups = $this->client->registry->findGroups($value);
        if(\count($groups) === 1) {
            return true;
        }
        
        if(\count($groups) === 0) {
            return false;
        }
        
        return \CharlotteDunois\Livia\Utils\DataHelpers::disambiguation($groups, 'groups', 'name').\PHP_EOL;
    }
50058
private static function validateFilter($value, $filter, $options, Validator $validator)
    {
        if (!is_string($value) || filter_var($value, $filter, $options) !== false) {
            return null;
        }

        // This workaround allows otherwise valid protocol relative urls to pass.
        // @see https://bugs.php.net/bug.php?id=72301
        if ($filter === FILTER_VALIDATE_URL && is_string($value) && strpos($value, '//') === 0) {
            if (filter_var('http:' . $value, $filter, $options) !== false) {
                return null;
            }
        }

        return error('The value must match the format {parameter}.', $validator);
    }
171456
protected function _validate_ext($value, $parameter)
    {
        if ($value === '') {
            return '';
        }

        $ext = pathinfo($value, PATHINFO_EXTENSION);
        return in_array(strtolower($ext), preg_split('#[\s,]+#', $parameter, -1, PREG_SPLIT_NO_EMPTY), true) ? $value : null;
    }
97607
public function isDateFormat($value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'date_format');

        if (!is_string($value) && !is_numeric($value)) {
            return false;
        }

        $date = DateTime::createFromFormat($parameters[0], $value);

        return $date && $date->format($parameters[0]) == $value;
    }
1326180
protected function _validate($attribute, $rule, $parameters, $value)
    {
        $srcValue = $value;

        if (isset($this->_validators[$rule])) {
            /** @noinspection VariableFunctionsUsageInspection */
            $value = call_user_func_array($this->_validators[$rule], [$value, $parameters]);
        } elseif (function_exists($rule)) {
            $value = call_user_func_array($rule, array_merge([$value], $parameters));
        } else {
            throw new FilterException(['`:name` rule is not be recognized', 'name' => $rule]);
        }

        if ($value === null) {
            if (is_string($this->_messages)) {
                if (strpos($this->_messages, '.') === false) {
                    $file = '@manaphp/Http/Validator/Messages/' . $this->_messages . '.php';
                } else {
                    $file = $this->_messages;
                }

                if (!$this->filesystem->fileExists($file)) {
                    throw new FilterException(['`:file` rule message template file is not exists', 'file' => $file]);
                }

                /** @noinspection PhpIncludeInspection */
                $this->_messages = require $this->alias->resolve($file);
            }

            if (isset($this->_messages[$rule])) {
                $message = [$this->_messages[$rule]];
            } else {
                $message = [$this->_defaultMessage];
            }

            $message['rule'] = $rule;
            $message['attribute'] = isset($this->_attributes[$attribute]) ? $this->_attributes[$attribute] : $attribute;
            $message['value'] = $srcValue;
            foreach ($parameters as $k => $parameter) {
                $message['parameters[' . $k . ']'] = $parameter;
            }

            throw new FilterException($message);
        }

        return $value;
    }
388645
public function validate($value, array $arguments = [])
    {
        $isString = is_string($value);
        $min = Arr::get($arguments, 'min', false);
        $max = Arr::get($arguments, 'max', false);
        $trim = Arr::get($arguments, 'trim', false);
        $striptags = Arr::get($arguments, 'striptags', false);
        $regex = Arr::get($arguments, 'regex', false);;
        $mask = Arr::get($arguments, 'mask', false);
        $strLower = Arr::get($arguments, 'str_lower', false);
        $strUpper = Arr::get($arguments, 'str_upper', false);
        $alphaNumeric = Arr::get($arguments, 'alpha_numeric', false);
        $email = Arr::get($arguments, 'email', false);
        $htmlEscape = Arr::get($arguments, 'html_escape', false);
        $inArray = Arr::get($arguments, 'in_array', false);
        $filter = Arr::get($arguments, 'filter', false);

        if (!$isString) {
            throw new Exception("O atributo '{$this->getAttribute()}' não é um string!");
        }

        if ($trim) {
            $value = trim($value);
            $value = preg_replace('/\s+/', ' ', $value);
        }

        if ($striptags) {
            if (is_bool($striptags) && $striptags) {
                $value = strip_tags($value);
            } elseif (is_string($striptags)) {
                $value = strip_tags($value, $striptags);
            } elseif (is_array($striptags)) {
                $value = strip_tags($value, implode("", $striptags));
            }
        }

        if ($strLower) {
            $value = strtolower($value);
        }

        if ($strUpper) {
            $value = strtoupper($value);
        }

        if ($htmlEscape) {
            $value = htmlspecialchars($value);
        }

        if ($alphaNumeric) {
            $value = preg_replace("/[^a-zA-Z0-9]+/", "", $value);
        }

        if ($email && !filter_var($value, FILTER_VALIDATE_EMAIL)) {
            throw new Exception("O atributo '{$this->getAttribute()}' não é um e-mail válido!");
        }

        $qntCaracteres = strlen($value);

        if ($min) {
            $min = intval($min);
        } else {
            $min = false;
        }

        if ($max) {
            $max = intval($max);
        } else {
            $max = false;
        }

        if ($min) {

            if ($qntCaracteres < $min) {
                throw new Exception(
                    "O atributo '{$this->getAttribute()}' deve ter no minimo '{$min}' caractere(s)!"
                );
            } elseif ($max && $qntCaracteres > $max) {
                throw new Exception(
                    "O atributo '{$this->getAttribute()}' deve ter no maximo '{$max}' caracteres!"
                );
            }

        }

        if ($regex && !preg_match($regex, $value)) {
            throw new Exception(
                "O atributo '{$this->getAttribute()}' não atende a validação regex!"
            );
        }

        if ($mask) {
            $valorNovo = '';
            $k = 0;
            for ($i = 0; $i <= strlen($mask) - 1; $i++) {
                if ($mask[$i] == '#') {
                    if (isset($value[$k])) {
                        $valorNovo .= $value[$k++];
                    }
                } else {
                    if (isset($mask[$i])) {
                        $valorNovo .= $mask[$i];
                    }
                }
            }
            $value = $valorNovo;

        }

        if ($inArray && !in_array($value, $inArray)) {
            throw new Exception("O atributo '{$this->getAttribute()}' não pertence ao conjunto de dados!");
        }

        if ($filter && $filter instanceof \Closure) {
            $value = $filter($value);
        } elseif ($filter) {
            $value = call_user_func($filter, $value);
        }

        return $value;
    }
103580
public function validate($args)
    {
        $matched = false;

        //validates arguments
        foreach ($args as $arg => $value) {
            //non-named option are skipped from validation
            if (is_numeric($arg)) continue;
            //validates action options
            foreach ($this->options as $option) {
                //checks if options matches specified parameter
                if ($option->matchParam($arg)) {
                    //validates option
                    if (!$option->validate($value)) {
                        throw new InvalidArgumentException($arg, $value);
                    }
                    $matched = true;
                }
            }
            if (!$matched) {
                throw new InvalidOptionException($arg);
            }
        }
        //validates required options
        foreach ($this->options as $option) {
            if (!$option->isRequired()) {
                continue;
            }

            if (!$option->getValue($args)) {
                throw new MissingRequiredArgumentException($option->getName());
            }
        }

        return true;
    }
1036365
protected function _validate_range($value, $parameter)
    {
        if (preg_match('#^(-?[\.\d]+)-(-?[\d\.]+)$#', $parameter, $match)) {
            return $value >= $match[1] && $value <= $match[2] ? $value : null;
        } else {
            throw new InvalidValueException(['range validator `:parameter` parameters is not {min}-{max} format', 'parameter' => $parameter]);
        }
    }
228305
public function validateDigitsBetween($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'digits_between');

        $length = strlen((string) $value);

        return ! preg_match('/[^0-9]/', $value)
                    && $length >= $parameters[0] && $length <= $parameters[1];
    }
1300924
protected function _validate_timestamp($value, $parameters)
    {
        $timestamp = is_numeric($value) ? (int)$value : strtotime($value);
        if ($timestamp === false) {
            return null;
        }

        if (isset($parameters[0])) {
            if ($parameters[0] === 'start') {
                /** @noinspection SummerTimeUnsafeTimeManipulationInspection */
                return (int)($timestamp / 86400) * 86400;
            } elseif ($parameters[0] === 'end') {
                /** @noinspection SummerTimeUnsafeTimeManipulationInspection */
                return (int)($timestamp / 86400) * 86400 + 86399;
            } else {
                return strtotime(date($parameters[0], $timestamp));
            }
        }

        return $timestamp;
    }
505159
public function whereHas($parameter, $value)
    {
        if (! $this->verify($parameter, $value)) {
            return true;
        }

        $this->search = $this->search
            ->whereHas($parameter, function ($query) use ($value) {
                $query->where('rbac_roles.id', $value);
            });
    }
978851
protected function validateBool($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        //$value = $this->getValue($parameter);

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

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

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

        if (!is_bool($value) && $value !== 'true' && $value !== 'false') {
            return Message::getMessage(Message::BOOL, [
                'param' => $parameter
            ]);
        }

        return null;
    }