diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index b4131af95305..71be2b698a55 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -200,10 +200,11 @@ 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 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, string $rule, array $errors = []): bool + public function check($value, $rule, array $errors = []): bool { $this->reset(); @@ -450,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 * 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..331545a1478d 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -376,10 +376,19 @@ you previously set, so ``setRules()``, ``setRuleGroup()`` etc. need to be repeat Validating 1 Value ================== -Validate one value against a rule: +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 +.. 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 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. +}