From e4990c3c37a6e5dfed8b0b20f80831e0612c03b3 Mon Sep 17 00:00:00 2001 From: Zhangqi Chen Date: Fri, 4 Aug 2023 16:52:57 +0800 Subject: [PATCH] enhance: Add TARGET_PARAMETER to Attribute for improved Validation --- src/Attributes/Validation/Accepted.php | 2 +- src/Attributes/Validation/AcceptedIf.php | 2 +- src/Attributes/Validation/ActiveUrl.php | 2 +- src/Attributes/Validation/After.php | 2 +- src/Attributes/Validation/AfterOrEqual.php | 2 +- src/Attributes/Validation/Alpha.php | 2 +- src/Attributes/Validation/AlphaDash.php | 2 +- src/Attributes/Validation/AlphaNumeric.php | 2 +- src/Attributes/Validation/ArrayType.php | 2 +- src/Attributes/Validation/Bail.php | 2 +- src/Attributes/Validation/Before.php | 2 +- src/Attributes/Validation/BeforeOrEqual.php | 2 +- src/Attributes/Validation/Between.php | 2 +- src/Attributes/Validation/BooleanType.php | 2 +- src/Attributes/Validation/Confirmed.php | 2 +- src/Attributes/Validation/CurrentPassword.php | 2 +- src/Attributes/Validation/Date.php | 2 +- src/Attributes/Validation/DateEquals.php | 4 ++-- src/Attributes/Validation/DateFormat.php | 2 +- src/Attributes/Validation/Different.php | 2 +- src/Attributes/Validation/Digits.php | 2 +- src/Attributes/Validation/DigitsBetween.php | 2 +- src/Attributes/Validation/Dimensions.php | 19 ++++++++++--------- src/Attributes/Validation/Distinct.php | 2 +- src/Attributes/Validation/Email.php | 8 ++++---- src/Attributes/Validation/EndsWith.php | 2 +- src/Attributes/Validation/Enum.php | 4 ++-- src/Attributes/Validation/Exclude.php | 2 +- src/Attributes/Validation/ExcludeIf.php | 7 ++++--- src/Attributes/Validation/ExcludeUnless.php | 7 ++++--- src/Attributes/Validation/ExcludeWithout.php | 5 +++-- src/Attributes/Validation/Exists.php | 2 +- src/Attributes/Validation/File.php | 2 +- src/Attributes/Validation/Filled.php | 2 +- src/Attributes/Validation/GreaterThan.php | 2 +- .../Validation/GreaterThanOrEqualTo.php | 2 +- src/Attributes/Validation/IP.php | 2 +- src/Attributes/Validation/IPv4.php | 2 +- src/Attributes/Validation/IPv6.php | 2 +- src/Attributes/Validation/Image.php | 2 +- src/Attributes/Validation/In.php | 2 +- src/Attributes/Validation/InArray.php | 5 +++-- src/Attributes/Validation/IntegerType.php | 2 +- src/Attributes/Validation/Json.php | 2 +- src/Attributes/Validation/LessThan.php | 5 +++-- .../Validation/LessThanOrEqualTo.php | 5 +++-- src/Attributes/Validation/Max.php | 2 +- src/Attributes/Validation/MimeTypes.php | 2 +- src/Attributes/Validation/Mimes.php | 2 +- src/Attributes/Validation/Min.php | 2 +- src/Attributes/Validation/MultipleOf.php | 2 +- src/Attributes/Validation/NotIn.php | 4 ++-- src/Attributes/Validation/NotRegex.php | 2 +- src/Attributes/Validation/Nullable.php | 2 +- src/Attributes/Validation/Numeric.php | 2 +- src/Attributes/Validation/Password.php | 11 ++++++----- src/Attributes/Validation/Present.php | 2 +- src/Attributes/Validation/Prohibited.php | 2 +- src/Attributes/Validation/ProhibitedIf.php | 2 +- .../Validation/ProhibitedUnless.php | 9 +++++---- src/Attributes/Validation/Prohibits.php | 2 +- src/Attributes/Validation/Regex.php | 4 ++-- src/Attributes/Validation/Required.php | 2 +- src/Attributes/Validation/RequiredIf.php | 9 +++++---- src/Attributes/Validation/RequiredUnless.php | 9 +++++---- src/Attributes/Validation/RequiredWith.php | 2 +- src/Attributes/Validation/RequiredWithAll.php | 2 +- src/Attributes/Validation/RequiredWithout.php | 2 +- .../Validation/RequiredWithoutAll.php | 2 +- src/Attributes/Validation/Rule.php | 2 +- src/Attributes/Validation/Same.php | 4 ++-- src/Attributes/Validation/Size.php | 4 ++-- src/Attributes/Validation/Sometimes.php | 2 +- src/Attributes/Validation/StartsWith.php | 2 +- src/Attributes/Validation/StringType.php | 2 +- src/Attributes/Validation/Timezone.php | 2 +- src/Attributes/Validation/Unique.php | 13 +++++++------ src/Attributes/Validation/Url.php | 2 +- src/Attributes/Validation/Uuid.php | 2 +- .../Validation/ValidationAttribute.php | 7 ++++--- 80 files changed, 138 insertions(+), 125 deletions(-) diff --git a/src/Attributes/Validation/Accepted.php b/src/Attributes/Validation/Accepted.php index 3894909b4..21b526544 100644 --- a/src/Attributes/Validation/Accepted.php +++ b/src/Attributes/Validation/Accepted.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Accepted extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/AcceptedIf.php b/src/Attributes/Validation/AcceptedIf.php index 054112319..4a88e0ba6 100644 --- a/src/Attributes/Validation/AcceptedIf.php +++ b/src/Attributes/Validation/AcceptedIf.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class AcceptedIf extends StringValidationAttribute { protected FieldReference $field; diff --git a/src/Attributes/Validation/ActiveUrl.php b/src/Attributes/Validation/ActiveUrl.php index 4987dda40..0186a1833 100644 --- a/src/Attributes/Validation/ActiveUrl.php +++ b/src/Attributes/Validation/ActiveUrl.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ActiveUrl extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/After.php b/src/Attributes/Validation/After.php index 9c60f91e0..ee6c0b0f9 100644 --- a/src/Attributes/Validation/After.php +++ b/src/Attributes/Validation/After.php @@ -6,7 +6,7 @@ use DateTimeInterface; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class After extends StringValidationAttribute { public function __construct(protected string|DateTimeInterface|FieldReference $date) diff --git a/src/Attributes/Validation/AfterOrEqual.php b/src/Attributes/Validation/AfterOrEqual.php index 1865ca94e..6f302b572 100644 --- a/src/Attributes/Validation/AfterOrEqual.php +++ b/src/Attributes/Validation/AfterOrEqual.php @@ -6,7 +6,7 @@ use DateTimeInterface; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class AfterOrEqual extends StringValidationAttribute { public function __construct(protected string|DateTimeInterface|RouteParameterReference $date) diff --git a/src/Attributes/Validation/Alpha.php b/src/Attributes/Validation/Alpha.php index 10e97d7eb..1a4ce8094 100644 --- a/src/Attributes/Validation/Alpha.php +++ b/src/Attributes/Validation/Alpha.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Alpha extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/AlphaDash.php b/src/Attributes/Validation/AlphaDash.php index 1e3afdcd5..d46d5aed1 100644 --- a/src/Attributes/Validation/AlphaDash.php +++ b/src/Attributes/Validation/AlphaDash.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class AlphaDash extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/AlphaNumeric.php b/src/Attributes/Validation/AlphaNumeric.php index c86cbfd4a..1a2091db2 100644 --- a/src/Attributes/Validation/AlphaNumeric.php +++ b/src/Attributes/Validation/AlphaNumeric.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class AlphaNumeric extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/ArrayType.php b/src/Attributes/Validation/ArrayType.php index 22c24f3fb..06337caf0 100644 --- a/src/Attributes/Validation/ArrayType.php +++ b/src/Attributes/Validation/ArrayType.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ArrayType extends StringValidationAttribute { protected array $keys; diff --git a/src/Attributes/Validation/Bail.php b/src/Attributes/Validation/Bail.php index f82880876..4d504de99 100644 --- a/src/Attributes/Validation/Bail.php +++ b/src/Attributes/Validation/Bail.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Bail extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Before.php b/src/Attributes/Validation/Before.php index ca049c7aa..11366abdc 100644 --- a/src/Attributes/Validation/Before.php +++ b/src/Attributes/Validation/Before.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Before extends StringValidationAttribute { public function __construct(protected string|DateTimeInterface|RouteParameterReference|FieldReference $date) diff --git a/src/Attributes/Validation/BeforeOrEqual.php b/src/Attributes/Validation/BeforeOrEqual.php index 6751f4ce4..700047a6c 100644 --- a/src/Attributes/Validation/BeforeOrEqual.php +++ b/src/Attributes/Validation/BeforeOrEqual.php @@ -6,7 +6,7 @@ use DateTimeInterface; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class BeforeOrEqual extends StringValidationAttribute { public function __construct(protected string | DateTimeInterface|RouteParameterReference $date) diff --git a/src/Attributes/Validation/Between.php b/src/Attributes/Validation/Between.php index 329361c34..1b45766ae 100644 --- a/src/Attributes/Validation/Between.php +++ b/src/Attributes/Validation/Between.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Between extends StringValidationAttribute { public function __construct(protected int|float|RouteParameterReference $min, protected int|float|RouteParameterReference $max) diff --git a/src/Attributes/Validation/BooleanType.php b/src/Attributes/Validation/BooleanType.php index 0c1f2fc26..40e42619f 100644 --- a/src/Attributes/Validation/BooleanType.php +++ b/src/Attributes/Validation/BooleanType.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class BooleanType extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Confirmed.php b/src/Attributes/Validation/Confirmed.php index a032c9daf..4c5e4117f 100644 --- a/src/Attributes/Validation/Confirmed.php +++ b/src/Attributes/Validation/Confirmed.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Confirmed extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/CurrentPassword.php b/src/Attributes/Validation/CurrentPassword.php index 03b42d19e..a8b7b9cb9 100644 --- a/src/Attributes/Validation/CurrentPassword.php +++ b/src/Attributes/Validation/CurrentPassword.php @@ -6,7 +6,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class CurrentPassword extends StringValidationAttribute { public function __construct(protected null|string|DummyBackedEnum|RouteParameterReference $guard = null) diff --git a/src/Attributes/Validation/Date.php b/src/Attributes/Validation/Date.php index b8ca815e6..b1074ffc6 100644 --- a/src/Attributes/Validation/Date.php +++ b/src/Attributes/Validation/Date.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Date extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/DateEquals.php b/src/Attributes/Validation/DateEquals.php index 6f239f393..430015393 100644 --- a/src/Attributes/Validation/DateEquals.php +++ b/src/Attributes/Validation/DateEquals.php @@ -6,10 +6,10 @@ use DateTimeInterface; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class DateEquals extends StringValidationAttribute { - public function __construct(protected string | DateTimeInterface|RouteParameterReference $date) + public function __construct(protected string|DateTimeInterface|RouteParameterReference $date) { } diff --git a/src/Attributes/Validation/DateFormat.php b/src/Attributes/Validation/DateFormat.php index ac18d8db2..e62287744 100644 --- a/src/Attributes/Validation/DateFormat.php +++ b/src/Attributes/Validation/DateFormat.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class DateFormat extends StringValidationAttribute { public function __construct(protected string $format) diff --git a/src/Attributes/Validation/Different.php b/src/Attributes/Validation/Different.php index 941cb6962..3c80fa2b7 100644 --- a/src/Attributes/Validation/Different.php +++ b/src/Attributes/Validation/Different.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Different extends StringValidationAttribute { protected FieldReference $field; diff --git a/src/Attributes/Validation/Digits.php b/src/Attributes/Validation/Digits.php index cd79b5079..661300962 100644 --- a/src/Attributes/Validation/Digits.php +++ b/src/Attributes/Validation/Digits.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Digits extends StringValidationAttribute { public function __construct(protected int|RouteParameterReference $value) diff --git a/src/Attributes/Validation/DigitsBetween.php b/src/Attributes/Validation/DigitsBetween.php index 2de51f6f2..9fbe13f8b 100644 --- a/src/Attributes/Validation/DigitsBetween.php +++ b/src/Attributes/Validation/DigitsBetween.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class DigitsBetween extends StringValidationAttribute { public function __construct(protected int|RouteParameterReference $min, protected int|RouteParameterReference $max) diff --git a/src/Attributes/Validation/Dimensions.php b/src/Attributes/Validation/Dimensions.php index 42b2f0a76..b20326c14 100644 --- a/src/Attributes/Validation/Dimensions.php +++ b/src/Attributes/Validation/Dimensions.php @@ -9,21 +9,22 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Dimensions extends ObjectValidationAttribute { protected BaseDimensions $rule; public function __construct( - null|int|RouteParameterReference $minWidth = null, - null|int|RouteParameterReference $minHeight = null, - null|int|RouteParameterReference $maxWidth = null, - null|int|RouteParameterReference $maxHeight = null, + null|int|RouteParameterReference $minWidth = null, + null|int|RouteParameterReference $minHeight = null, + null|int|RouteParameterReference $maxWidth = null, + null|int|RouteParameterReference $maxHeight = null, null|float|string|RouteParameterReference $ratio = null, - null|int|RouteParameterReference $width = null, - null|int|RouteParameterReference $height = null, - null|BaseDimensions $rule = null, - ) { + null|int|RouteParameterReference $width = null, + null|int|RouteParameterReference $height = null, + null|BaseDimensions $rule = null, + ) + { $minWidth = $this->normalizePossibleRouteReferenceParameter($minWidth); $minHeight = $this->normalizePossibleRouteReferenceParameter($minHeight); $maxWidth = $this->normalizePossibleRouteReferenceParameter($maxWidth); diff --git a/src/Attributes/Validation/Distinct.php b/src/Attributes/Validation/Distinct.php index 3e9002e9b..0f294cd97 100644 --- a/src/Attributes/Validation/Distinct.php +++ b/src/Attributes/Validation/Distinct.php @@ -6,7 +6,7 @@ use Spatie\LaravelData\Exceptions\CannotBuildValidationRule; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Distinct extends StringValidationAttribute { public const Strict = 'strict'; diff --git a/src/Attributes/Validation/Email.php b/src/Attributes/Validation/Email.php index 4a054588b..31be6cf12 100644 --- a/src/Attributes/Validation/Email.php +++ b/src/Attributes/Validation/Email.php @@ -8,7 +8,7 @@ use Spatie\LaravelData\Exceptions\CannotBuildValidationRule; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Email extends StringValidationAttribute { public const RfcValidation = 'rfc'; @@ -32,15 +32,15 @@ public static function keyword(): string public function parameters(): array { return collect($this->modes) - ->whenEmpty(fn (Collection $modes) => $modes->add(self::RfcValidation)) - ->filter(fn (string $mode) => in_array($mode, [ + ->whenEmpty(fn(Collection $modes) => $modes->add(self::RfcValidation)) + ->filter(fn(string $mode) => in_array($mode, [ self::RfcValidation, self::NoRfcWarningsValidation, self::DnsCheckValidation, self::SpoofCheckValidation, self::FilterEmailValidation, ])) - ->whenEmpty(fn () => throw CannotBuildValidationRule::create("Email validation rule needs at least one valid mode.")) + ->whenEmpty(fn() => throw CannotBuildValidationRule::create("Email validation rule needs at least one valid mode.")) ->all(); } } diff --git a/src/Attributes/Validation/EndsWith.php b/src/Attributes/Validation/EndsWith.php index 59462c8ba..31313cfaf 100644 --- a/src/Attributes/Validation/EndsWith.php +++ b/src/Attributes/Validation/EndsWith.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class EndsWith extends StringValidationAttribute { protected string|array $values; diff --git a/src/Attributes/Validation/Enum.php b/src/Attributes/Validation/Enum.php index 5be5ad10c..9bef9f6a6 100644 --- a/src/Attributes/Validation/Enum.php +++ b/src/Attributes/Validation/Enum.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Enum extends ObjectValidationAttribute { protected EnumRule $rule; @@ -16,7 +16,7 @@ public function __construct(string|EnumRule|RouteParameterReference $enum) { $this->rule = $enum instanceof EnumRule ? $enum - : new EnumRule((string) $enum); + : new EnumRule((string)$enum); } public static function keyword(): string diff --git a/src/Attributes/Validation/Exclude.php b/src/Attributes/Validation/Exclude.php index 3fb0c3000..15cf1276a 100644 --- a/src/Attributes/Validation/Exclude.php +++ b/src/Attributes/Validation/Exclude.php @@ -6,7 +6,7 @@ use Illuminate\Validation\Rules\ExcludeIf; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Exclude extends ObjectValidationAttribute { public function __construct(protected ExcludeIf $rule) diff --git a/src/Attributes/Validation/ExcludeIf.php b/src/Attributes/Validation/ExcludeIf.php index 249006c7e..bba48e5b3 100644 --- a/src/Attributes/Validation/ExcludeIf.php +++ b/src/Attributes/Validation/ExcludeIf.php @@ -7,15 +7,16 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ExcludeIf extends StringValidationAttribute { protected FieldReference $field; public function __construct( - string|FieldReference $field, + string|FieldReference $field, protected string|int|float|bool|BackedEnum|RouteParameterReference $value - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/ExcludeUnless.php b/src/Attributes/Validation/ExcludeUnless.php index 3603a6fa4..304a86f34 100644 --- a/src/Attributes/Validation/ExcludeUnless.php +++ b/src/Attributes/Validation/ExcludeUnless.php @@ -7,15 +7,16 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ExcludeUnless extends StringValidationAttribute { protected FieldReference $field; public function __construct( - string|FieldReference $field, + string|FieldReference $field, protected string|int|float|bool|BackedEnum|RouteParameterReference $value - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/ExcludeWithout.php b/src/Attributes/Validation/ExcludeWithout.php index 2cfee1c5c..8abb0c733 100644 --- a/src/Attributes/Validation/ExcludeWithout.php +++ b/src/Attributes/Validation/ExcludeWithout.php @@ -5,14 +5,15 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ExcludeWithout extends StringValidationAttribute { protected FieldReference $field; public function __construct( string|FieldReference $field, - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/Exists.php b/src/Attributes/Validation/Exists.php index 424826ab8..4d744f786 100644 --- a/src/Attributes/Validation/Exists.php +++ b/src/Attributes/Validation/Exists.php @@ -9,7 +9,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Exists extends ObjectValidationAttribute { protected BaseExists $rule; diff --git a/src/Attributes/Validation/File.php b/src/Attributes/Validation/File.php index 6c2ed45f1..14eb8c84a 100644 --- a/src/Attributes/Validation/File.php +++ b/src/Attributes/Validation/File.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class File extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Filled.php b/src/Attributes/Validation/Filled.php index ea0fd36eb..599d2dd52 100644 --- a/src/Attributes/Validation/Filled.php +++ b/src/Attributes/Validation/Filled.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Filled extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/GreaterThan.php b/src/Attributes/Validation/GreaterThan.php index 31a9d3b27..388cdf675 100644 --- a/src/Attributes/Validation/GreaterThan.php +++ b/src/Attributes/Validation/GreaterThan.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class GreaterThan extends StringValidationAttribute { protected FieldReference $field; diff --git a/src/Attributes/Validation/GreaterThanOrEqualTo.php b/src/Attributes/Validation/GreaterThanOrEqualTo.php index 3a78ff4e7..3dc92eba5 100644 --- a/src/Attributes/Validation/GreaterThanOrEqualTo.php +++ b/src/Attributes/Validation/GreaterThanOrEqualTo.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class GreaterThanOrEqualTo extends StringValidationAttribute { protected FieldReference $field; diff --git a/src/Attributes/Validation/IP.php b/src/Attributes/Validation/IP.php index 3e3f7cab5..28b7f2406 100644 --- a/src/Attributes/Validation/IP.php +++ b/src/Attributes/Validation/IP.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class IP extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/IPv4.php b/src/Attributes/Validation/IPv4.php index d1138a843..371af3df0 100644 --- a/src/Attributes/Validation/IPv4.php +++ b/src/Attributes/Validation/IPv4.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class IPv4 extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/IPv6.php b/src/Attributes/Validation/IPv6.php index 313b1af67..ab04a1d33 100644 --- a/src/Attributes/Validation/IPv6.php +++ b/src/Attributes/Validation/IPv6.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class IPv6 extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Image.php b/src/Attributes/Validation/Image.php index c5ec3fe89..f39712267 100644 --- a/src/Attributes/Validation/Image.php +++ b/src/Attributes/Validation/Image.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Image extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/In.php b/src/Attributes/Validation/In.php index 53ca55316..81f74d72d 100644 --- a/src/Attributes/Validation/In.php +++ b/src/Attributes/Validation/In.php @@ -8,7 +8,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class In extends ObjectValidationAttribute { protected BaseIn $rule; diff --git a/src/Attributes/Validation/InArray.php b/src/Attributes/Validation/InArray.php index 37f105cc0..33c4b86e1 100644 --- a/src/Attributes/Validation/InArray.php +++ b/src/Attributes/Validation/InArray.php @@ -5,14 +5,15 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class InArray extends StringValidationAttribute { protected FieldReference $field; public function __construct( string|FieldReference $field, - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/IntegerType.php b/src/Attributes/Validation/IntegerType.php index 74ccaae77..03c89ce0b 100644 --- a/src/Attributes/Validation/IntegerType.php +++ b/src/Attributes/Validation/IntegerType.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class IntegerType extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Json.php b/src/Attributes/Validation/Json.php index d42afb173..9c1725fc0 100644 --- a/src/Attributes/Validation/Json.php +++ b/src/Attributes/Validation/Json.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Json extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/LessThan.php b/src/Attributes/Validation/LessThan.php index 5ba17b340..67c40c761 100644 --- a/src/Attributes/Validation/LessThan.php +++ b/src/Attributes/Validation/LessThan.php @@ -5,14 +5,15 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class LessThan extends StringValidationAttribute { protected FieldReference $field; public function __construct( string|FieldReference $field, - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/LessThanOrEqualTo.php b/src/Attributes/Validation/LessThanOrEqualTo.php index ebd1e670e..bc4ef6b44 100644 --- a/src/Attributes/Validation/LessThanOrEqualTo.php +++ b/src/Attributes/Validation/LessThanOrEqualTo.php @@ -5,14 +5,15 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class LessThanOrEqualTo extends StringValidationAttribute { protected FieldReference $field; public function __construct( string|FieldReference $field, - ) { + ) + { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/Max.php b/src/Attributes/Validation/Max.php index 71d177950..364ed3c82 100644 --- a/src/Attributes/Validation/Max.php +++ b/src/Attributes/Validation/Max.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Max extends StringValidationAttribute { public function __construct(protected int|RouteParameterReference $value) diff --git a/src/Attributes/Validation/MimeTypes.php b/src/Attributes/Validation/MimeTypes.php index e05aaf174..1da693c6b 100644 --- a/src/Attributes/Validation/MimeTypes.php +++ b/src/Attributes/Validation/MimeTypes.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class MimeTypes extends StringValidationAttribute { protected array $mimeTypes; diff --git a/src/Attributes/Validation/Mimes.php b/src/Attributes/Validation/Mimes.php index 8d568d3ed..66a36f0fb 100644 --- a/src/Attributes/Validation/Mimes.php +++ b/src/Attributes/Validation/Mimes.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Mimes extends StringValidationAttribute { protected array $mimes; diff --git a/src/Attributes/Validation/Min.php b/src/Attributes/Validation/Min.php index f1684a46f..c9f91effa 100644 --- a/src/Attributes/Validation/Min.php +++ b/src/Attributes/Validation/Min.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Min extends StringValidationAttribute { public function __construct(protected int|RouteParameterReference $value) diff --git a/src/Attributes/Validation/MultipleOf.php b/src/Attributes/Validation/MultipleOf.php index 0b29b2ea5..86025edcd 100644 --- a/src/Attributes/Validation/MultipleOf.php +++ b/src/Attributes/Validation/MultipleOf.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class MultipleOf extends StringValidationAttribute { public function __construct(protected int|float|RouteParameterReference $value) diff --git a/src/Attributes/Validation/NotIn.php b/src/Attributes/Validation/NotIn.php index 2ac0c7cb3..4b935862b 100644 --- a/src/Attributes/Validation/NotIn.php +++ b/src/Attributes/Validation/NotIn.php @@ -8,7 +8,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class NotIn extends ObjectValidationAttribute { protected BaseNotIn $rule; @@ -22,7 +22,7 @@ public function __construct(array|string|BaseNotIn|RouteParameterReference ...$v } $values = array_map( - fn (string|RouteParameterReference $value) => $this->normalizePossibleRouteReferenceParameter($value), + fn(string|RouteParameterReference $value) => $this->normalizePossibleRouteReferenceParameter($value), Arr::flatten($values) ); diff --git a/src/Attributes/Validation/NotRegex.php b/src/Attributes/Validation/NotRegex.php index c7d624456..75455c865 100644 --- a/src/Attributes/Validation/NotRegex.php +++ b/src/Attributes/Validation/NotRegex.php @@ -5,7 +5,7 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class NotRegex extends StringValidationAttribute { public function __construct(protected string|RouteParameterReference $pattern) diff --git a/src/Attributes/Validation/Nullable.php b/src/Attributes/Validation/Nullable.php index 8d8258f13..46e87dc6c 100644 --- a/src/Attributes/Validation/Nullable.php +++ b/src/Attributes/Validation/Nullable.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Nullable extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Numeric.php b/src/Attributes/Validation/Numeric.php index 7bb18e592..2f3fd195d 100644 --- a/src/Attributes/Validation/Numeric.php +++ b/src/Attributes/Validation/Numeric.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Numeric extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Password.php b/src/Attributes/Validation/Password.php index b72ed033d..a6e0886b8 100644 --- a/src/Attributes/Validation/Password.php +++ b/src/Attributes/Validation/Password.php @@ -8,22 +8,23 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Password extends ObjectValidationAttribute { protected BasePassword $rule; public function __construct( - int|RouteParameterReference $min = 12, + int|RouteParameterReference $min = 12, bool|RouteParameterReference $letters = false, bool|RouteParameterReference $mixedCase = false, bool|RouteParameterReference $numbers = false, bool|RouteParameterReference $symbols = false, bool|RouteParameterReference $uncompromised = false, - int|RouteParameterReference $uncompromisedThreshold = 0, + int|RouteParameterReference $uncompromisedThreshold = 0, bool|RouteParameterReference $default = false, - ?BasePassword $rule = null, - ) { + ?BasePassword $rule = null, + ) + { $min = $this->normalizePossibleRouteReferenceParameter($min); $letters = $this->normalizePossibleRouteReferenceParameter($letters); $mixedCase = $this->normalizePossibleRouteReferenceParameter($mixedCase); diff --git a/src/Attributes/Validation/Present.php b/src/Attributes/Validation/Present.php index 0b273eaf4..a73ea81a9 100644 --- a/src/Attributes/Validation/Present.php +++ b/src/Attributes/Validation/Present.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Present extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Prohibited.php b/src/Attributes/Validation/Prohibited.php index 62392630d..b3df2f84c 100644 --- a/src/Attributes/Validation/Prohibited.php +++ b/src/Attributes/Validation/Prohibited.php @@ -6,7 +6,7 @@ use Illuminate\Validation\Rules\ProhibitedIf; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Prohibited extends ObjectValidationAttribute { public function __construct(protected ?ProhibitedIf $rule = null) diff --git a/src/Attributes/Validation/ProhibitedIf.php b/src/Attributes/Validation/ProhibitedIf.php index fd65d6a86..9aedf10f1 100644 --- a/src/Attributes/Validation/ProhibitedIf.php +++ b/src/Attributes/Validation/ProhibitedIf.php @@ -8,7 +8,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ProhibitedIf extends StringValidationAttribute { protected FieldReference $field; diff --git a/src/Attributes/Validation/ProhibitedUnless.php b/src/Attributes/Validation/ProhibitedUnless.php index 7a2e7ca2c..4ed8f5a0a 100644 --- a/src/Attributes/Validation/ProhibitedUnless.php +++ b/src/Attributes/Validation/ProhibitedUnless.php @@ -8,7 +8,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class ProhibitedUnless extends StringValidationAttribute { protected FieldReference $field; @@ -16,9 +16,10 @@ class ProhibitedUnless extends StringValidationAttribute protected string|array $values; public function __construct( - string|FieldReference $field, - array | string | BackedEnum | RouteParameterReference ...$values - ) { + string|FieldReference $field, + array|string|BackedEnum|RouteParameterReference ...$values + ) + { $this->field = $this->parseFieldReference($field); $this->values = Arr::flatten($values); } diff --git a/src/Attributes/Validation/Prohibits.php b/src/Attributes/Validation/Prohibits.php index 61104a3c5..5f6397e5c 100644 --- a/src/Attributes/Validation/Prohibits.php +++ b/src/Attributes/Validation/Prohibits.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Prohibits extends StringValidationAttribute { protected array $fields; diff --git a/src/Attributes/Validation/Regex.php b/src/Attributes/Validation/Regex.php index 7ab578c20..0ea8c2846 100644 --- a/src/Attributes/Validation/Regex.php +++ b/src/Attributes/Validation/Regex.php @@ -5,10 +5,10 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Regex extends StringValidationAttribute { - public function __construct(protected string | RouteParameterReference $pattern) + public function __construct(protected string|RouteParameterReference $pattern) { } diff --git a/src/Attributes/Validation/Required.php b/src/Attributes/Validation/Required.php index 4f341638a..5cde323ab 100644 --- a/src/Attributes/Validation/Required.php +++ b/src/Attributes/Validation/Required.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\RequiringRule; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Required extends ObjectValidationAttribute implements RequiringRule { public function __construct(protected ?RequiredIf $rule = null) diff --git a/src/Attributes/Validation/RequiredIf.php b/src/Attributes/Validation/RequiredIf.php index 8ac45ee5a..5ac3b4f83 100644 --- a/src/Attributes/Validation/RequiredIf.php +++ b/src/Attributes/Validation/RequiredIf.php @@ -9,7 +9,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredIf extends StringValidationAttribute implements RequiringRule { protected FieldReference $field; @@ -17,9 +17,10 @@ class RequiredIf extends StringValidationAttribute implements RequiringRule protected string|array $values; public function __construct( - string|FieldReference $field, - array|string|BackedEnum | RouteParameterReference ...$values - ) { + string|FieldReference $field, + array|string|BackedEnum|RouteParameterReference ...$values + ) + { $this->field = $this->parseFieldReference($field); $this->values = Arr::flatten($values); } diff --git a/src/Attributes/Validation/RequiredUnless.php b/src/Attributes/Validation/RequiredUnless.php index a6c42b472..511d36ae0 100644 --- a/src/Attributes/Validation/RequiredUnless.php +++ b/src/Attributes/Validation/RequiredUnless.php @@ -9,7 +9,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredUnless extends StringValidationAttribute implements RequiringRule { protected FieldReference $field; @@ -17,9 +17,10 @@ class RequiredUnless extends StringValidationAttribute implements RequiringRule protected string|array $values; public function __construct( - string|FieldReference $field, - array|string|BackedEnum | RouteParameterReference ...$values - ) { + string|FieldReference $field, + array|string|BackedEnum|RouteParameterReference ...$values + ) + { $this->field = $this->parseFieldReference($field); $this->values = Arr::flatten($values); } diff --git a/src/Attributes/Validation/RequiredWith.php b/src/Attributes/Validation/RequiredWith.php index cbd3a711e..6a77933ce 100644 --- a/src/Attributes/Validation/RequiredWith.php +++ b/src/Attributes/Validation/RequiredWith.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredWith extends StringValidationAttribute implements RequiringRule { protected array $fields; diff --git a/src/Attributes/Validation/RequiredWithAll.php b/src/Attributes/Validation/RequiredWithAll.php index 5910af25c..2f9add3d6 100644 --- a/src/Attributes/Validation/RequiredWithAll.php +++ b/src/Attributes/Validation/RequiredWithAll.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredWithAll extends StringValidationAttribute implements RequiringRule { protected array $fields; diff --git a/src/Attributes/Validation/RequiredWithout.php b/src/Attributes/Validation/RequiredWithout.php index 7d2182fab..6f72eedc8 100644 --- a/src/Attributes/Validation/RequiredWithout.php +++ b/src/Attributes/Validation/RequiredWithout.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredWithout extends StringValidationAttribute implements RequiringRule { protected array $fields; diff --git a/src/Attributes/Validation/RequiredWithoutAll.php b/src/Attributes/Validation/RequiredWithoutAll.php index ff1f2945c..d13b728df 100644 --- a/src/Attributes/Validation/RequiredWithoutAll.php +++ b/src/Attributes/Validation/RequiredWithoutAll.php @@ -7,7 +7,7 @@ use Spatie\LaravelData\Support\Validation\References\FieldReference; use Spatie\LaravelData\Support\Validation\RequiringRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class RequiredWithoutAll extends StringValidationAttribute implements RequiringRule { protected array $fields; diff --git a/src/Attributes/Validation/Rule.php b/src/Attributes/Validation/Rule.php index 0aa3faae2..2cd9025a9 100644 --- a/src/Attributes/Validation/Rule.php +++ b/src/Attributes/Validation/Rule.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Validation\ValidationRule as ValidationRuleContract; use Spatie\LaravelData\Support\Validation\ValidationRule; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Rule extends ValidationRule { /** @var array */ diff --git a/src/Attributes/Validation/Same.php b/src/Attributes/Validation/Same.php index 7b20362be..97fbe0b5a 100644 --- a/src/Attributes/Validation/Same.php +++ b/src/Attributes/Validation/Same.php @@ -5,12 +5,12 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\FieldReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Same extends StringValidationAttribute { protected FieldReference $field; - public function __construct(string | FieldReference $field) + public function __construct(string|FieldReference $field) { $this->field = $this->parseFieldReference($field); } diff --git a/src/Attributes/Validation/Size.php b/src/Attributes/Validation/Size.php index 7be1b9a73..72dd88c65 100644 --- a/src/Attributes/Validation/Size.php +++ b/src/Attributes/Validation/Size.php @@ -5,10 +5,10 @@ use Attribute; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Size extends StringValidationAttribute { - public function __construct(protected int | RouteParameterReference $size) + public function __construct(protected int|RouteParameterReference $size) { } diff --git a/src/Attributes/Validation/Sometimes.php b/src/Attributes/Validation/Sometimes.php index 6c2d0310b..51b4924b9 100644 --- a/src/Attributes/Validation/Sometimes.php +++ b/src/Attributes/Validation/Sometimes.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Sometimes extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/StartsWith.php b/src/Attributes/Validation/StartsWith.php index 59695659a..a6b2069e0 100644 --- a/src/Attributes/Validation/StartsWith.php +++ b/src/Attributes/Validation/StartsWith.php @@ -6,7 +6,7 @@ use Illuminate\Support\Arr; use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class StartsWith extends StringValidationAttribute { protected string|array $values; diff --git a/src/Attributes/Validation/StringType.php b/src/Attributes/Validation/StringType.php index 814ba30b4..55e995b76 100644 --- a/src/Attributes/Validation/StringType.php +++ b/src/Attributes/Validation/StringType.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class StringType extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Timezone.php b/src/Attributes/Validation/Timezone.php index b8763afc2..10cfddab7 100644 --- a/src/Attributes/Validation/Timezone.php +++ b/src/Attributes/Validation/Timezone.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Timezone extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Unique.php b/src/Attributes/Validation/Unique.php index a00f59c50..47c6ff719 100644 --- a/src/Attributes/Validation/Unique.php +++ b/src/Attributes/Validation/Unique.php @@ -9,7 +9,7 @@ use Spatie\LaravelData\Support\Validation\References\RouteParameterReference; use Spatie\LaravelData\Support\Validation\ValidationPath; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Unique extends ObjectValidationAttribute { protected BaseUnique $rule; @@ -20,11 +20,12 @@ public function __construct( null|string|RouteParameterReference $connection = null, null|string|RouteParameterReference $ignore = null, null|string|RouteParameterReference $ignoreColumn = null, - bool|RouteParameterReference $withoutTrashed = false, - string|RouteParameterReference $deletedAtColumn = 'deleted_at', - ?Closure $where = null, - ?BaseUnique $rule = null - ) { + bool|RouteParameterReference $withoutTrashed = false, + string|RouteParameterReference $deletedAtColumn = 'deleted_at', + ?Closure $where = null, + ?BaseUnique $rule = null + ) + { $table = $this->normalizePossibleRouteReferenceParameter($table); $column = $this->normalizePossibleRouteReferenceParameter($column); $connection = $this->normalizePossibleRouteReferenceParameter($connection); diff --git a/src/Attributes/Validation/Url.php b/src/Attributes/Validation/Url.php index e10a35980..743c8723d 100644 --- a/src/Attributes/Validation/Url.php +++ b/src/Attributes/Validation/Url.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Url extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/Uuid.php b/src/Attributes/Validation/Uuid.php index 1ce57b8ed..d9b6eb6e0 100644 --- a/src/Attributes/Validation/Uuid.php +++ b/src/Attributes/Validation/Uuid.php @@ -4,7 +4,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] class Uuid extends StringValidationAttribute { public static function keyword(): string diff --git a/src/Attributes/Validation/ValidationAttribute.php b/src/Attributes/Validation/ValidationAttribute.php index cbc3e110b..6428347ff 100644 --- a/src/Attributes/Validation/ValidationAttribute.php +++ b/src/Attributes/Validation/ValidationAttribute.php @@ -22,7 +22,7 @@ public function __toString(): string protected static function parseDateValue(mixed $value): mixed { - if (! is_string($value)) { + if (!is_string($value)) { return $value; } @@ -41,7 +41,7 @@ protected static function parseDateValue(mixed $value): mixed protected static function parseBooleanValue(mixed $value): mixed { - if (! is_string($value)) { + if (!is_string($value)) { return $value; } @@ -58,7 +58,8 @@ protected static function parseBooleanValue(mixed $value): mixed protected function parseFieldReference( string|FieldReference $reference - ): FieldReference { + ): FieldReference + { return $reference instanceof FieldReference ? $reference : new FieldReference($reference);