-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add list
and associative_array
types to Type
constraint
#52954
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
Conversation
e9a2a0b
to
bfe542d
Compare
src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php
Outdated
Show resolved
Hide resolved
Let's add |
710571f
to
ecb57d7
Compare
Please update the PR title + description to reflect the additional option, thanks |
list
type to Type
constraintlist
and associative_array
types to Type
constraint
ecb57d7
to
5ab4068
Compare
Thank you @hermann8u. |
in php any array is associative ;) |
@hermann8u i fail to see what usecase would allow for [1 => some], but not [0 => some] |
@ro0NL I don't know, maybe when 1 is an id for example? I'm currently working on an other PR that add a constraint to validate array keys that could be used in association with this one. |
@ro0NL Ok I got your point finally. What you mean is that list are also associative_array? |
Hello!
This PR aims to add support for
list
type in theType
constraint.This is done by using the new PHP 8.1 function
array_is_list
, after checking that the value is an array withis_array
function.Here is an example of use:
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 :An
associative_array
is an array that is not a list. Moreover, this means that an empty array will not be considered as anassociative_array
.Best regards