From d0ad8d1263820a6d4c537d7af020b1970e4a100e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E5=BE=B7=E9=93=AD?= Date: Sat, 28 Feb 2026 15:28:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(validation):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=99=A8=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E4=BB=A5=E6=94=AF=E6=8C=81null=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改ErrorMessageTrait中的getMessage方法参数类型顺序 - 更新ScopedValidatorsTrait中fileValidator方法的suffixes参数类型 - 更新ScopedValidatorsTrait中imageValidator方法的suffixes参数类型 - 更新ScopedValidatorsTrait中mimesValidator方法的types参数类型 - 调整Validators类中float方法的min和max参数类型顺序 - 调整Validators类中integer方法的min和max参数类型顺序 - 调整Validators类中int方法的min和max参数类型顺序 - 调整Validators类中number方法的min和max参数类型顺序 - 调整Validators类中num方法的min和max参数类型顺序 - 调整Validators类中string方法的maxLen参数类型顺序 - 调整Validators类中size方法的min和max参数类型顺序 - 调整Validators类中between方法的min和max参数类型顺序 - 调整Validators类中range方法的min和max参数类型顺序 - 调整Validators类中length方法的minLen和maxLen参数类型顺序 - 调整Validators类中regexp方法的default参数类型 - 调整Validators类中regex方法的default参数类型 --- src/Traits/ErrorMessageTrait.php | 2 +- src/Traits/ScopedValidatorsTrait.php | 6 +++--- src/Validators.php | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Traits/ErrorMessageTrait.php b/src/Traits/ErrorMessageTrait.php index 97e612d..4bccbe8 100644 --- a/src/Traits/ErrorMessageTrait.php +++ b/src/Traits/ErrorMessageTrait.php @@ -304,7 +304,7 @@ public function setMessages(array $messages): static * * @return string */ - public function getMessage(callable|string $validator, string $field, array $args = [], array|string $message = null): string + public function getMessage(callable|string $validator, string $field, array $args = [], null|array|string $message = null): string { $rawName = is_string($validator) ? $validator : 'callback'; $params = [ diff --git a/src/Traits/ScopedValidatorsTrait.php b/src/Traits/ScopedValidatorsTrait.php index d7692cb..7b0c02e 100644 --- a/src/Traits/ScopedValidatorsTrait.php +++ b/src/Traits/ScopedValidatorsTrait.php @@ -342,7 +342,7 @@ public function requiredWithoutAll(string $field, mixed $fieldVal, array|string * * @return bool */ - public function fileValidator(string $field, array|string $suffixes = null): bool + public function fileValidator(string $field, null|array|string $suffixes = null): bool { if (!$file = $this->uploadedFiles[$field] ?? null) { return false; @@ -373,7 +373,7 @@ public function fileValidator(string $field, array|string $suffixes = null): boo * * @return bool */ - public function imageValidator(string $field, array|string $suffixes = null): bool + public function imageValidator(string $field, null|array|string $suffixes = null): bool { if (!$file = $this->uploadedFiles[$field] ?? null) { return false; @@ -452,7 +452,7 @@ public function mimeTypesValidator(string $field, array|string $types): bool * * @todo */ - public function mimesValidator(string $field, array|string $types = null): void + public function mimesValidator(string $field, null|array|string $types = null): void { } diff --git a/src/Validators.php b/src/Validators.php index f20ad97..2888fe1 100644 --- a/src/Validators.php +++ b/src/Validators.php @@ -197,7 +197,7 @@ public static function bool(mixed $val): bool * * @return bool */ - public static function float(mixed $val, float|string|int $min = null, string|float|int $max = null, string|int $flags = 0): bool + public static function float(mixed $val, null|float|string|int $min = null, null|string|float|int $max = null, string|int $flags = 0): bool { if (!is_numeric($val)) { return false; @@ -254,7 +254,7 @@ public static function float(mixed $val, float|string|int $min = null, string|fl * // 'default' => 3, // value to return if the filter fails * ] */ - public static function integer(mixed $val, int|string $min = null, int|string $max = null, int|string $flags = 0): bool + public static function integer(mixed $val, null|int|string $min = null, null|int|string $max = null, int|string $flags = 0): bool { if (!is_numeric($val)) { return false; @@ -298,7 +298,7 @@ public static function integer(mixed $val, int|string $min = null, int|string $m * @return bool * @see integer() */ - public static function int(mixed $val, float|int|string $min = null, float|int|string $max = null, string|int $flags = 0): bool + public static function int(mixed $val, null|float|int|string $min = null, null|float|int|string $max = null, string|int $flags = 0): bool { return self::integer($val, $min, $max, $flags); } @@ -313,7 +313,7 @@ public static function int(mixed $val, float|int|string $min = null, float|int|s * * @return bool */ - public static function number(mixed $val, float|int|string $min = null, float|int|string $max = null, string|int $flags = 0): bool + public static function number(mixed $val, null|float|int|string $min = null, null|float|int|string $max = null, string|int $flags = 0): bool { if (!is_numeric($val)) { return false; @@ -335,7 +335,7 @@ public static function number(mixed $val, float|int|string $min = null, float|in * @return bool * @see number() */ - public static function num(mixed $val, float|int|string $min = null, float|int|string $max = null, string|int $flags = 0): bool + public static function num(mixed $val, null|float|int|string $min = null, null|float|int|string $max = null, string|int $flags = 0): bool { return self::number($val, $min, $max, $flags); } @@ -349,7 +349,7 @@ public static function num(mixed $val, float|int|string $min = null, float|int|s * * @return bool */ - public static function string(mixed $val, float|int|string $minLen = 0, float|int|string $maxLen = null): bool + public static function string(mixed $val, float|int|string $minLen = 0, null|float|int|string $maxLen = null): bool { if (!is_string($val)) { return false; @@ -564,7 +564,7 @@ public static function max(array|int|string $val, int|string $maxRange): bool * * @return bool */ - public static function size(float|array|int|string $val, float|int|string $min = null, float|int|string $max = null): bool + public static function size(float|array|int|string $val, null|float|int|string $min = null, null|float|int|string $max = null): bool { if (!is_numeric($val)) { if (is_string($val)) { @@ -589,7 +589,7 @@ public static function size(float|array|int|string $val, float|int|string $min = * @return bool * @see Validators::size() */ - public static function between(float|array|int|string $val, int|string $min = null, int|string $max = null): bool + public static function between(float|array|int|string $val, null|int|string $min = null, null|int|string $max = null): bool { return self::size($val, $min, $max); } @@ -602,7 +602,7 @@ public static function between(float|array|int|string $val, int|string $min = nu * @return bool * @see Validators::size() */ - public static function range(float|array|int|string $val, int|string $min = null, int|string $max = null): bool + public static function range(float|array|int|string $val, null|int|string $min = null, null|int|string $max = null): bool { return self::size($val, $min, $max); } @@ -616,7 +616,7 @@ public static function range(float|array|int|string $val, int|string $min = null * * @return bool */ - public static function length(array|string $val, float|int|string $minLen = 0, float|int|string $maxLen = null): bool + public static function length(array|string $val, null|float|int|string $minLen = 0, null|float|int|string $maxLen = null): bool { if (!is_string($val) && !is_array($val)) { return false; @@ -712,7 +712,7 @@ public static function contains(mixed $val, array|int|string $needle): bool * * @return bool */ - public static function regexp(float|int|string $val, string $regexp, $default = null): bool + public static function regexp(float|int|string $val, string $regexp, null $default = null): bool { $options = [ 'regexp' => $regexp @@ -734,7 +734,7 @@ public static function regexp(float|int|string $val, string $regexp, $default = * * @return bool */ - public static function regex(float|int|string $val, string $regexp, $default = null): bool + public static function regex(float|int|string $val, string $regexp, null $default = null): bool { return self::regexp($val, $regexp, $default); }