8000 [Validator] Deprecated the Size constraint in favor of MinCount and MaxCount by webmozart · Pull Request #4851 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Deprecated the Size constraint in favor of MinCount and MaxCount #4851

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

Merged
merged 4 commits into from
Jul 11, 2012

Conversation

webmozart
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

This PR cleans up with the current ambiguity between

  • Min
  • Max
  • MinLength
  • MaxLength
  • Range
  • Size

in the following ways:

  • The Range constraint was removed again as it can be completely replaced by Min and Max.
  • The Size constraint was reverted to it's 2.0 feature set and deprecated.
  • The constraints MinCount and MaxCount were added to make up for the functionality that was added to Size.

@@ -1136,6 +1136,26 @@
private $recursiveCollection;
```

* The `Size` constraint was deprecated and will be removed in Symfony 2.1. You should
Copy link
Member

Choose a reason for hiding this comment

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

should be 2.3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

fabpot added a commit that referenced this pull request Jul 11, 2012
Commits
-------

0be602d [Validator] Deprecated the Size constraint
d661837 [Validator] Reverted the changes done to the Size constraint in 3a5e84f
d84b689 [Validator] Added the constraints MinCount and MaxCount
1a732e4 [Validator] Removed the Range constraint as it duplicates functionality given in Min and Max

Discussion
----------

[Validator] Deprecated the Size constraint in favor of MinCount and MaxCount

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

This PR cleans up with the current ambiguity between

* Min
* Max
* MinLength
* MaxLength
* Range
* Size

in the following ways:

* The Range constraint was removed again as it can be completely replaced by Min and Max.
* The Size constraint was reverted to it's 2.0 feature set and deprecated.
* The constraints MinCount and MaxCount were added to make up for the functionality that was added to Size.
@fabpot fabpot merged commit 0be602d into symfony:master Jul 11, 2012
@Tobion
Copy link
Contributor
Tobion commented Jul 11, 2012

I thought you would deprecate the other way round because it's more flexible. So e.g. Range in favor of Min and Max.

Say my collection should contain excatly 8 elements so constraint MinCount(8) and MaxCount(8).
Given 7 elements the raised error is wrong as it would say the collection should contain 8 elements or more.
The problem is that the min constraint doesnt know anything about the max constraint.
With a size contraint it could automatically adjust the message according the the options. It would also allow to add further options in the future like specifiyng only even/odd numbers are allowed.

@webmozart
Copy link
Contributor Author

Good points. I created a new PR that is referenced above.

fabpot added a commit that referenced this pull request Jul 12, 2012
Commits
-------

a92f80b [Validator] Added Length constraint and deprecated MinLength and MaxLength
83a3f75 [Validator] Deprecated the constraints Min and Max in favor of Range
0cdacee [Validator] Removed MinCount and MaxCount and replaced them by the constraint Count
741c147 [Validator] Renamed deprecated Size constraint to Range

Discussion
----------

[Validator] Reintroduced Range constraint and created Count and Length constraints

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

After @Tobion's comment to #4851, this is the next try to streamline the constraints and reduce duplication of logic. The downside of the current MinLength/MaxLength and MinCount/MaxCount pairs is that they cannot output a fitting error message if a value should have an *exact* length/count. So this PR introduces

* Range (formerly Size) to replace Min/Max
* Count to replace MinCount/MaxCount
* Length to replace MinLength/MaxLength

Feedback is appreciated.

---------------------------------------------------------------------------

by Tobion at 2012-07-11T20:40:08Z

The `choice` constraint also cannot handle `min = max`. Or maybe we don't need these options on choice anymore as we can achieve the same with the new `count` constraint?!

---------------------------------------------------------------------------

by beberlei at 2012-07-12T08:59:44Z

Dude, nobody has time to fix the BC breaks you introduce :-)

---------------------------------------------------------------------------

by TomAdam at 2012-07-12T12:38:49Z

The changes to the `Size` validator yesterday broke my project, and I started rewriting to use `MaxLength / MinLength` validators today, until I spotted this. It would be good if this PR could have a reasonably high priority (whether or not it is accepted) as it will change how I fix my issues. I suspect a lot of people using the master branch will be in the same situation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0