Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Validator] NewDivisibleBy constraint for testing divisibility#28069
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[Validator] NewDivisibleBy constraint for testing divisibility#28069
Uh oh!
There was an error while loading.Please reload this page.
Conversation
b96bb3a tof8cf896CompareMultipleOf constraint for testing divisibilityf8cf896 to36e369eComparecolinodell commentedJul 26, 2018
The AppVeyor failure seems to be unrelated to this change. |
weaverryan left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice job Colin! I just tested this in a real project - no missing pieces - it works great :).
colinodell commentedAug 9, 2018
Thanks Ryan! I'm currently using this in an application with a "time spent" field which only accepts 0.25 hour increments. I feel like having a |
nicolas-grekas commentedAug 10, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What about renaming to |
xabbuh commentedAug 10, 2018
I agree with Nicolas. And since the test in Twig is named the same that would feel more consistent. |
colinodell commentedAug 10, 2018
Thanks for the feedback@nicolas-grekas! I have renamed the constraint and updated the docs PR accordingly. |
MultipleOf constraint for testing divisibilityDivisibleBy constraint for testing divisibility| self::NOT_DIVISIBLE_BY => 'NOT_MULTIPLE_OF', | ||
| ); | ||
| public $message = 'This value should be divisible by {{ compared_value }}.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Would be nice to also add translations for this string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The message is also not all that clear from a user's perspective. To a developer "8 is divisible by 2" makes sense, but a mathematician would say "so is 7.6543", and a common user would just be like "erm keep the math out of my way".
I'd stick with the more genericThis value must be a multiple of {{ compared_value }}. for the end-user feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I have updated the message as requested and force-pushed the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I have also added translation strings in English and Spanish.
| const NOT_DIVISIBLE_BY = '6d99d6c3-1464-4ccf-bdc7-14d083cf455c'; | ||
| protected static $errorNames = array( | ||
| self::NOT_DIVISIBLE_BY => 'NOT_MULTIPLE_OF', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Forgot to update the constant value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Fixed and force-pushed. Thanks for catching this!
bb9feb7 to6eff196Comparecurry684 commentedAug 13, 2018
For Dutch (nl): <trans-unitid="84"> <source>This value should be a multiple of {{ compared_value }}.</source> <target>Deze waarde moet een veelvoud zijn van {{ compared_value }}.</target> </trans-unit> |
dmaicher commentedAug 13, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
For German (de): |
xabbuh commentedAug 13, 2018
@dmaicher Though we need to capitalise the
|
colinodell commentedAug 13, 2018
I have added the two translations (but now fabbot is failing due to an existing translation) |
curry684 commentedAug 13, 2018
The correction is wrong.@fabpot you should probably exempt |
| */ | ||
| protected function compareValues($value1, $value2) | ||
| { | ||
| return 0 == fmod($value1, $value2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
let's use strict comparison here
nicolas-grekas left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For french:Cette valeur doit être un multiple de {{ compared_value }}.
colinodell commentedAug 14, 2018
Thanks for the feedback@nicolas-grekas! I have made the comparison strict and added the French translation. |
3993781 toefcfb8bCompare…ivisibility (colinodell)This PR was squashed before being merged into the 4.2-dev branch (closes#28069).Discussion----------[Validator] New `DivisibleBy` constraint for testing divisibilityThis introduces a new ~`MultipleOf`~ `DivisibleBy` constraint which checks whether one number is a multiple of (aka "divisible by") some other number. Useful for enforcing specific increments on a number.| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | n/a| License | MIT| Doc PR |symfony/symfony-docs#10121Seesymfony/symfony-docs#10121 for examples of this constraint in action.Commits-------efcfb8b [Validator] New `DivisibleBy` constraint for testing divisibility
…ell)This PR was merged into the master branch.Discussion----------[Validator] Document the DivisibleBy constraintDocumentation for the new ~`MultipleOf`~ `DivisibleBy` constraint proposed insymfony/symfony#28069Commits-------3270cca Document the DivisibleBy constraint
Uh oh!
There was an error while loading.Please reload this page.
This introduces a new
MultipleOfDivisibleByconstraint which checks whether one number is a multiple of (aka "divisible by") some other number. Useful for enforcing specific increments on a number.Seesymfony/symfony-docs#10121 for examples of this constraint in action.