Skip to content

Commit 410b7a9

Browse files
committed
docs: add changelog and upgrade
1 parent 09e194d commit 410b7a9

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

user_guide_src/source/changelogs/v4.4.4.rst

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Release Date: Unreleased
1414
BREAKING
1515
********
1616

17+
Validation with Dot Array Syntax
18+
================================
19+
20+
A validation rule with the wildcard ``*`` now validates only data in correct
21+
dimensions as "dot array syntax".
22+
See :ref:`Upgrading <upgrade-444-validation-with-dot-array-syntax>` for details.
23+
1724
***************
1825
Message Changes
1926
***************

user_guide_src/source/installation/upgrade_444.rst

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ Mandatory File Changes
2020
Breaking Changes
2121
****************
2222

23+
.. _upgrade-444-validation-with-dot-array-syntax:
24+
25+
Validation with Dot Array Syntax
26+
================================
27+
28+
If you are using :ref:`dot array syntax <validation-dot-array-syntax>` in validation
29+
rules, a bug where ``*`` would validate data in incorrect dimensions has been fixed.
30+
31+
In previous versions, the rule key ``contacts.*.name`` captured data with any
32+
level like ``contacts.*.name``, ``contacts.*.*.name``, ``contacts.*.*.*.name``,
33+
etc., incorrectly.
34+
35+
The following code explains details:
36+
37+
.. literalinclude:: upgrade_444/001.php
38+
:lines: 2-
39+
40+
If you have code that depends on the bug, fix the the rule key.
41+
2342
*********************
2443
Breaking Enhancements
2544
*********************
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use Config\Services;
4+
5+
$validation = Services::validation();
6+
7+
$data = [
8+
'contacts' => [
9+
'name' => 'Joe Smith',
10+
'just' => [
11+
'friends' => [
12+
['name' => 'SATO Taro'],
13+
['name' => 'Li Ming'],
14+
['name' => 'Heinz Müller'],
15+
],
16+
],
17+
],
18+
];
19+
20+
$validation->setRules(
21+
['contacts.*.name' => 'required|max_length[8]']
22+
);
23+
24+
$validation->run($data); // false
25+
26+
d($validation->getErrors());
27+
/*
28+
Before: Captured `contacts.*.*.*.name` incorrectly.
29+
[
30+
contacts.just.friends.0.name => "The contacts.*.name field cannot exceed 8 characters in length.",
31+
contacts.just.friends.2.name => "The contacts.*.name field cannot exceed 8 characters in length.",
32+
]
33+
34+
After: Captures no data for `contacts.*.name`.
35+
[
36+
contacts.*.name => string (38) "The contacts.*.name field is required.",
37+
]
38+
*/

user_guide_src/source/libraries/validation.rst

+6
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ To give a labeled error message you can set up as:
314314
.. note:: ``setRules()`` will overwrite any rules that were set previously. To add more than one
315315
rule to an existing set of rules, use ``setRule()`` multiple times.
316316

317+
.. _validation-dot-array-syntax:
318+
317319
Setting Rules for Array Data
318320
============================
319321

@@ -328,6 +330,10 @@ You can use the ``*`` wildcard symbol to match any one level of the array:
328330
.. literalinclude:: validation/010.php
329331
:lines: 2-
330332

333+
.. note:: Prior to v4.4.4, due to a bug, the wildcard ``*`` validated data in incorrect
334+
dimensions. See :ref:`Upgrading <upgrade-444-validation-with-dot-array-syntax>`
335+
for details.
336+
331337
"dot array syntax" can also be useful when you have single dimension array data.
332338
For example, data returned by multi select dropdown:
333339

0 commit comments

Comments
 (0)