From df78be589b98f288c900a04a069cb95b34137e63 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 11 Dec 2023 03:53:34 +0200 Subject: [PATCH] Introduce various validation rule attributes Added new validation rule attributes including ascii, decimal, gte (greater than or equal), lte (less than or equal), mime type, missing, and present. These attributes enhance the robustness and specificity of data validation across the application. --- src/Attributes/Validation/Ascii.php | 19 +++++++++ src/Attributes/Validation/Decimal.php | 24 +++++++++++ .../Validation/GreaterThanOrEqual.php | 29 ++++++++++++++ src/Attributes/Validation/LessThanOrEqual.php | 29 ++++++++++++++ .../Validation/MimeTypeByFileExtension.php | 25 ++++++++++++ src/Attributes/Validation/Missing.php | 19 +++++++++ src/Attributes/Validation/MissingIf.php | 39 ++++++++++++++++++ src/Attributes/Validation/MissingUnless.php | 40 +++++++++++++++++++ src/Attributes/Validation/MissingWith.php | 33 +++++++++++++++ src/Attributes/Validation/MissingWithAll.php | 33 +++++++++++++++ src/Attributes/Validation/Negative.php | 19 +++++++++ src/Attributes/Validation/Positive.php | 19 +++++++++ src/Attributes/Validation/PresentIf.php | 39 ++++++++++++++++++ src/Attributes/Validation/PresentUnless.php | 40 +++++++++++++++++++ src/Attributes/Validation/PresentWith.php | 33 +++++++++++++++ src/Attributes/Validation/PresentWithAll.php | 33 +++++++++++++++ 16 files changed, 473 insertions(+) create mode 100644 src/Attributes/Validation/Ascii.php create mode 100644 src/Attributes/Validation/Decimal.php create mode 100644 src/Attributes/Validation/GreaterThanOrEqual.php create mode 100644 src/Attributes/Validation/LessThanOrEqual.php create mode 100644 src/Attributes/Validation/MimeTypeByFileExtension.php create mode 100644 src/Attributes/Validation/Missing.php create mode 100644 src/Attributes/Validation/MissingIf.php create mode 100644 src/Attributes/Validation/MissingUnless.php create mode 100644 src/Attributes/Validation/MissingWith.php create mode 100644 src/Attributes/Validation/MissingWithAll.php create mode 100644 src/Attributes/Validation/Negative.php create mode 100644 src/Attributes/Validation/Positive.php create mode 100644 src/Attributes/Validation/PresentIf.php create mode 100644 src/Attributes/Validation/PresentUnless.php create mode 100644 src/Attributes/Validation/PresentWith.php create mode 100644 src/Attributes/Validation/PresentWithAll.php diff --git a/src/Attributes/Validation/Ascii.php b/src/Attributes/Validation/Ascii.php new file mode 100644 index 00000000..87f76f91 --- /dev/null +++ b/src/Attributes/Validation/Ascii.php @@ -0,0 +1,19 @@ +min, $this->max]); + } +} diff --git a/src/Attributes/Validation/GreaterThanOrEqual.php b/src/Attributes/Validation/GreaterThanOrEqual.php new file mode 100644 index 00000000..9c9f2cc4 --- /dev/null +++ b/src/Attributes/Validation/GreaterThanOrEqual.php @@ -0,0 +1,29 @@ +field = $this->parseFieldReference($field); + } + + + public static function keyword(): string + { + return 'gte'; + } + + public function parameters(): array + { + return [$this->field]; + } +} diff --git a/src/Attributes/Validation/LessThanOrEqual.php b/src/Attributes/Validation/LessThanOrEqual.php new file mode 100644 index 00000000..67e42bad --- /dev/null +++ b/src/Attributes/Validation/LessThanOrEqual.php @@ -0,0 +1,29 @@ +field = $this->parseFieldReference($field); + } + + + public static function keyword(): string + { + return 'lte'; + } + + public function parameters(): array + { + return [$this->field]; + } +} diff --git a/src/Attributes/Validation/MimeTypeByFileExtension.php b/src/Attributes/Validation/MimeTypeByFileExtension.php new file mode 100644 index 00000000..0aab4412 --- /dev/null +++ b/src/Attributes/Validation/MimeTypeByFileExtension.php @@ -0,0 +1,25 @@ +types); + } +} diff --git a/src/Attributes/Validation/Missing.php b/src/Attributes/Validation/Missing.php new file mode 100644 index 00000000..efe87938 --- /dev/null +++ b/src/Attributes/Validation/Missing.php @@ -0,0 +1,19 @@ +field = $this->parseFieldReference($field); + $this->values = Arr::flatten($values); + } + + public static function keyword(): string + { + return 'missing_if'; + } + + public function parameters(): array + { + return [ + $this->field, + $this->values, + ]; + } +} diff --git a/src/Attributes/Validation/MissingUnless.php b/src/Attributes/Validation/MissingUnless.php new file mode 100644 index 00000000..1cb167ea --- /dev/null +++ b/src/Attributes/Validation/MissingUnless.php @@ -0,0 +1,40 @@ +field = $this->parseFieldReference($field); + $this->values = Arr::flatten($values); + } + + + public static function keyword(): string + { + return 'missing_unless'; + } + + public function parameters(): array + { + return [ + $this->field, + $this->values, + ]; + } +} diff --git a/src/Attributes/Validation/MissingWith.php b/src/Attributes/Validation/MissingWith.php new file mode 100644 index 00000000..383edb61 --- /dev/null +++ b/src/Attributes/Validation/MissingWith.php @@ -0,0 +1,33 @@ +fields[] = $field instanceof FieldReference ? $field : new FieldReference($field); + } + } + + public static function keyword(): string + { + return 'missing_with'; + } + + public function parameters(): array + { + return [ + $this->fields, + ]; + } +} diff --git a/src/Attributes/Validation/MissingWithAll.php b/src/Attributes/Validation/MissingWithAll.php new file mode 100644 index 00000000..65146eb8 --- /dev/null +++ b/src/Attributes/Validation/MissingWithAll.php @@ -0,0 +1,33 @@ +fields[] = $field instanceof FieldReference ? $field : new FieldReference($field); + } + } + + public static function keyword(): string + { + return 'missing_with_all'; + } + + public function parameters(): array + { + return [ + $this->fields, + ]; + } +} diff --git a/src/Attributes/Validation/Negative.php b/src/Attributes/Validation/Negative.php new file mode 100644 index 00000000..9dd02008 --- /dev/null +++ b/src/Attributes/Validation/Negative.php @@ -0,0 +1,19 @@ +field = $this->parseFieldReference($field); + $this->values = Arr::flatten($values); + } + + public static function keyword(): string + { + return 'present_if'; + } + + public function parameters(): array + { + return [ + $this->field, + $this->values, + ]; + } +} diff --git a/src/Attributes/Validation/PresentUnless.php b/src/Attributes/Validation/PresentUnless.php new file mode 100644 index 00000000..b2743ba9 --- /dev/null +++ b/src/Attributes/Validation/PresentUnless.php @@ -0,0 +1,40 @@ +field = $this->parseFieldReference($field); + $this->values = Arr::flatten($values); + } + + + public static function keyword(): string + { + return 'present_unless'; + } + + public function parameters(): array + { + return [ + $this->field, + $this->values, + ]; + } +} diff --git a/src/Attributes/Validation/PresentWith.php b/src/Attributes/Validation/PresentWith.php new file mode 100644 index 00000000..f269533a --- /dev/null +++ b/src/Attributes/Validation/PresentWith.php @@ -0,0 +1,33 @@ +fields[] = $field instanceof FieldReference ? $field : new FieldReference($field); + } + } + + public static function keyword(): string + { + return 'present_with'; + } + + public function parameters(): array + { + return [ + $this->fields, + ]; + } +} diff --git a/src/Attributes/Validation/PresentWithAll.php b/src/Attributes/Validation/PresentWithAll.php new file mode 100644 index 00000000..0fc3a5cd --- /dev/null +++ b/src/Attributes/Validation/PresentWithAll.php @@ -0,0 +1,33 @@ +fields[] = $field instanceof FieldReference ? $field : new FieldReference($field); + } + } + + public static function keyword(): string + { + return 'present_with_all'; + } + + public function parameters(): array + { + return [ + $this->fields, + ]; + } +}