Commit 6f1f88f
committed
feature symfony#52954 [Validator] Add
This PR was squashed before being merged into the 7.1 branch.
Discussion
----------
[Validator] Add `list` and `associative_array` types to `Type` constraint
| Q | A
| ------------- | ---
| Branch? | 7.1
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
Hello!
This PR aims to add support for `list` type in the `Type`constraint.
This is done by using the *new* PHP 8.1 function `array_is_list`, after checking that the value is an array with `is_array` function.
Here is an example of use:
```php
#[Assert\Type('list')]
private $value;
```
I consider doing an other PR to add `associative_array` type aswell. Or if you think it's ok, I can also add it in an other commit on this one.
--- UPDATE
After fabpot comment, I added an other commit to support `associative_array` type aswell :
```php
#[Assert\Type('associative_array')]
private $value;
```
An `associative_array` is an array that is not a list. Moreover, this means that an empty array will not be considered as an `associative_array`.
Best regards
Commits
-------
5ab4068 [Validator] Add `list` and `associative_array` types to `Type` constraintlist and associative_array types to Type constraint (Florian Hermann)File tree
3 files changed
+19
-0
lines changed- src/Symfony/Component/Validator
- Constraints
- Tests/Constraints
3 files changed
+19
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
166 | 170 | | |
167 | 171 | | |
168 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| |||
0 commit comments