From 3c3227a608dab6edf95418ee1afac02d8ffb5f06 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Apr 2023 15:14:51 +0900 Subject: [PATCH 1/4] fix: Validation:check() parameter $rule type It should accept an array. --- system/Validation/Validation.php | 3 ++- user_guide_src/source/changelogs/v4.4.0.rst | 5 ++++- user_guide_src/source/installation/upgrade_440.rst | 5 ++++- user_guide_src/source/libraries/validation.rst | 8 +++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index b4131af95305..118752c29355 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -201,9 +201,10 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup * determining whether validation was successful or not. * * @param array|bool|float|int|object|string|null $value + * @param array|string $rule * @param string[] $errors */ - public function check($value, string $rule, array $errors = []): bool + public function check($value, $rule, array $errors = []): bool { $this->reset(); diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst index ccb48b873edc..df5b2c6da321 100644 --- a/user_guide_src/source/changelogs/v4.4.0.rst +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -39,7 +39,10 @@ Interface Changes Method Signature Changes ======================== -- The third parameter ``Routing $routing`` has been added to ``RouteCollection::__construct()``. +- **Routing:** The third parameter ``Routing $routing`` has been added to + ``RouteCollection::__construct()``. +- **Validation:** The method signature of ``Validation::check()`` has been changed. + The ``string`` typehint on the ``$rule`` parameter was removed. Enhancements ************ diff --git a/user_guide_src/source/installation/upgrade_440.rst b/user_guide_src/source/installation/upgrade_440.rst index 9d7d002d6efc..6f1a2b3d675c 100644 --- a/user_guide_src/source/installation/upgrade_440.rst +++ b/user_guide_src/source/installation/upgrade_440.rst @@ -78,9 +78,12 @@ The Cookie config items in **app/Config/App.php** are no longer used. Breaking Enhancements ********************* -- The method signature of ``RouteCollection::__construct()`` has been changed. +- **Routing:** The method signature of ``RouteCollection::__construct()`` has been changed. The third parameter ``Routing $routing`` has been added. Extending classes should likewise add the parameter so as not to break LSP. +- **Validation:** The method signature of ``Validation::check()`` has been changed. + The ``string`` typehint on the ``$rule`` parameter was removed. Extending classes + should likewise remove the typehint so as not to break LSP. Project Files ************* diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 2c9b5cb6994f..044d8769dc52 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -376,10 +376,16 @@ you previously set, so ``setRules()``, ``setRuleGroup()`` etc. need to be repeat Validating 1 Value ================== -Validate one value against a rule: +Validate one value against the rules: .. literalinclude:: validation/012.php +.. note:: Prior to v4.4.0, this method's second parameter, ``$rule``, was + typehinted to accept ``string``. In v4.4.0 and after, the typehint was + removed to allow arrays, too. + +.. note:: This method calls the ``setRule()`` method to set the rules internally. + .. _validation-getting-validated-data: Getting Validated Data From d1d6482d6623248cb46457e3fe511efcfdf9e8af Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Apr 2023 15:16:29 +0900 Subject: [PATCH 2/4] docs: improve sample code --- user_guide_src/source/libraries/validation/012.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/validation/012.php b/user_guide_src/source/libraries/validation/012.php index a43f9ab1a498..9b9e89c21c87 100644 --- a/user_guide_src/source/libraries/validation/012.php +++ b/user_guide_src/source/libraries/validation/012.php @@ -1,3 +1,5 @@ check($value, 'required'); +if ($validation->check($value, 'required')) { + // $value is valid. +} From a492f04f30ae1c8b67744ce0105067ebba00597f Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Apr 2023 15:25:36 +0900 Subject: [PATCH 3/4] docs: add doc comments --- system/Validation/Validation.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 118752c29355..71be2b698a55 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -200,9 +200,9 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup * Runs the validation process, returning true or false * determining whether validation was successful or not. * - * @param array|bool|float|int|object|string|null $value - * @param array|string $rule - * @param string[] $errors + * @param array|bool|float|int|object|string|null $value The data to validate. + * @param array|string $rule The validation rules. + * @param string[] $errors The custom error message. */ public function check($value, $rule, array $errors = []): bool { @@ -451,7 +451,8 @@ public function withRequest(RequestInterface $request): ValidationInterface * 'rule' => 'message', * ] * - * @param array|string $rules + * @param array|string $rules The validation rules. + * @param array $errors The custom error message. * * @return $this * From 2962b16473a1e6dcc67cd34b87ff4f4d280a3598 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Apr 2023 15:30:46 +0900 Subject: [PATCH 4/4] docs: add check() method parameter explanation --- user_guide_src/source/libraries/validation.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 044d8769dc52..331545a1478d 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -376,7 +376,10 @@ you previously set, so ``setRules()``, ``setRuleGroup()`` etc. need to be repeat Validating 1 Value ================== -Validate one value against the rules: +The ``check()`` method validates one value against the rules. +The first parameter ``$value`` is the value to validate. The second parameter +``$rule`` is the validation rules. +The optional third parameter ``$errors`` is the the custom error message. .. literalinclude:: validation/012.php