-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add the divisibleBy option to the Count constraint #35783
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
src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf
Outdated
Show resolved
Hide resolved
785c4e0
to
8dfb7b2
Compare
What issue does this fix considering we already have a dedicated contraint? |
Currently you have to do everything manually: new Callback(static function ($collection, ExecutionContextInterface $context): void {
$context
->getValidator()
->inContext($context)
->validate(\count($collection), new DivisibleBy([
'value' => 3,
]));
}), |
What about supporting countable in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/DivisibleByValidator.php#L21 this instead? |
I thought about this but |
Why not? :) |
That implies way more work and it’s also less logical to use from a DX POV.
The collection « count » is divisible by X, not the collection itself. My
collection cannot be « greater than » X, it’s an array/object. Its « count
» must be minimum X. Etc. I’m sure the Count constraint was made for this.
…On Wed 19 Feb 2020 at 18:37, Jules Pietri ***@***.***> wrote:
Why not? :)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#35783?email_source=notifications&email_token=AA35DBYJFWYIW5N4XZS2VATRDVU6JA5CNFSM4KXT2VJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMIXO5I#issuecomment-588347253>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA35DB72WPRA5LJ3WAQPVILRDVU6JANCNFSM4KXT2VJA>
.
|
It is usually different, but when an object is countable, this is just the same thing. |
I think this approach (this PR) is more clear to me also. |
Thank you @fancyweb. |
From my experience, it is sometimes useful to assert that the number of elements in a collection is a multiple of X.