Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] add number constraints#28637

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

Merged

Conversation

@jschaedl
Copy link
Contributor

@jschaedljschaedl commentedSep 29, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#28608
LicenseMIT
Doc PRsymfony/symfony-docs#11254

I added the following constraints:

  • Positive
  • PositiveOrZero
  • Negative
  • NegativeOrZero

ro0NL, OskarStark, and andreybolonin reacted with thumbs up emoji
@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from6f25560 to5a92e1bCompareSeptember 29, 2018 18:43
@nicolas-grekasnicolas-grekas added this to thenext milestoneSep 29, 2018
@ostrolucky
Copy link
Contributor

What about null values?

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from5a92e1b to0b6e408CompareSeptember 30, 2018 07:05
@jschaedl
Copy link
ContributorAuthor

@ostrolucky I think it should do nothing for null values. I will add a condition and a test.

@xabbuh
Copy link
Member

I think we could save plenty of code here if the constraints were just specialised versions of the already existingRange constraint. WDYT?

@ro0NL
Copy link
Contributor

likePositive extends Range?

@xabbuh
Copy link
Member

yes

@ostrolucky
Copy link
Contributor

Better fit is GreaterThan*/LessThan*. No new validators would be required then

OskarStark, jschaedl, and theofidry reacted with thumbs up emoji

@xabbuh
Copy link
Member

indeed, those fit better thanRange

@jschaedl
Copy link
ContributorAuthor

@ostrolucky Do you mean we don't need the newPositive*/Negative* validators at all and users should use the already existingGreaterThan*/LessThan* validators?

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from73e1e81 to43aef65CompareOctober 5, 2018 08:40
@jschaedl
Copy link
ContributorAuthor

@xabbuh@ro0NL I changed thePositiveValidator which is now extending theGreaterThanValidator. Is this what you had in mind?

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from43aef65 to40aa6cdCompareOctober 5, 2018 08:43
@ro0NL
Copy link
Contributor

@jschaedl actually i expected it like:

class Postive extends GreaterThan {   public function __construct() {       parent::__construct(array('min' => 1));   }}

thenPostive is validated byGreaterThanValidator as regular.

ostrolucky, xabbuh, and Destroy666x reacted with thumbs up emoji

@ostrolucky
Copy link
Contributor

Yep, like@ro0NL says. Well, not exactly (validatedBy needs to be specified and minimum value maybe tweaked) but mostly just that.

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch 2 times, most recently from84de93c to63fa241CompareNovember 2, 2018 08:51
Copy link
Contributor

@OskarStarkOskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice improvement

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from63fa241 tod2073e5CompareNovember 7, 2018 07:17
Copy link
Contributor

@ostroluckyostrolucky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Like I explained in#28637 (comment) since these constraints don't accept any default value, their constructor shouldn't default tonull

@ro0NL
Copy link
Contributor

IMHO it should, so we get the expected exception herehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraint.php#L136

Also we could makemessage the default option for these :)

@ostrolucky
Copy link
Contributor

ostrolucky commentedNov 16, 2018
edited
Loading

These constraints are designed in a way they will never passnull to parent.

It would make some sense in case message is default property, but I don't think somebody would approve such change.

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from8f7388a to2c07ac2CompareNovember 30, 2018 08:10
@jschaedljschaedlforce-pushed thevalidator-number_constraints branch 2 times, most recently from7119701 to35bfa5aCompareDecember 1, 2018 22:57
@jschaedljschaedlforce-pushed thevalidator-number_constraints branch from189d578 to0e31c3bCompareMarch 17, 2019 21:34
@jschaedljschaedlforce-pushed thevalidator-number_constraints branch frome476040 toc77ef3bCompareMarch 22, 2019 11:09
Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ready to be merged after the translation files are fixed.

@OskarStark
Copy link
Contributor

@jschaedl could you please send a Docs PR for this new feature?
Thank you

@jschaedljschaedlforce-pushed thevalidator-number_constraints branch 2 times, most recently frome718297 toc973ceeCompareMarch 31, 2019 16:48
@jschaedl
Copy link
ContributorAuthor

@OskarStark I am already working on it. :-)

OskarStark reacted with heart emoji

@fabpotfabpotforce-pushed thevalidator-number_constraints branch fromc973cee to0187039CompareMarch 31, 2019 17:19
@fabpot
Copy link
Member

Thank you@jschaedl.

jschaedl reacted with hooray emoji

@fabpotfabpot merged commit0187039 intosymfony:masterMar 31, 2019
fabpot added a commit that referenced this pull requestMar 31, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes#28637).Discussion----------[Validator] add number constraints| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#28608| License       | MIT| Doc PR        | tbd.I added the following constraints:* `Positive`* `PositiveOrZero`* `Negative`* `NegativeOrZero`Commits-------0187039 [Validator] add number constraints
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestApr 5, 2019
This PR was squashed before being merged into the master branch (closes#11254).Discussion----------[Validator] Add docs for number constraintsFeature PR:symfony/symfony#28637- [x] Positive- [x] PositiveOrZero- [x] Negative- [x] NegativeOrZero### Todo:- [x] find a better example for `NegativeOrZero` constraintCommits-------8022292 [Validator] Add docs for number constraints
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
@jschaedljschaedl deleted the validator-number_constraints branchFebruary 23, 2020 08:03
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@OskarStarkOskarStarkOskarStark approved these changes

@xabbuhxabbuhxabbuh left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@ro0NLro0NLro0NL left review comments

@ostroluckyostroluckyostrolucky requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

8 participants

@jschaedl@ostrolucky@xabbuh@ro0NL@OskarStark@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp