Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Validation::check() does not accept array rules #7424

Merged
merged 4 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
*
Expand Down
5 changes: 4 additions & 1 deletion user_guide_src/source/changelogs/v4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
************
Expand Down
5 changes: 4 additions & 1 deletion user_guide_src/source/installation/upgrade_440.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
*************
Expand Down
11 changes: 10 additions & 1 deletion user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/libraries/validation/012.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

$validation->check($value, 'required');
if ($validation->check($value, 'required')) {
// $value is valid.
}