-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add an integer constraint and validator #11076
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
|
||
namespace Symfony\Component\Validator\Tests\Constraints; | ||
|
||
use DateTime; |
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.
Usually in Symfony's codebase global classes used without importing them.
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 think it's ugly, but okay, fixed.
if this gets into core, you need to add an entry for new feature to CHANGELOG2.5.txt and add similar entries to the CHANGELOG.txt of the component as well. All of this besides writing the documentation PR. |
@cordoval, you meant 2.6, right? |
yes, we are already missing several features that are due to 2.6, please create a new file. You rock @elnur like a .pro 😊 |
@cordoval, I've added an entry to the component's |
Related to #6799 and #10221 (discussion as of here). |
@elnur I think I understand the problem you're solving, but I'm not very fond of the solution. Let's look at the simplest case: $validator->validate($value, new Integer());
$validator->validate($value, new Type('int')); I personally would expect both validators to do the same. Maybe this should instead be solved by adding an option "strict" to Type? // requires an actual integer
$validator->validate($value, new Type('int'));
// requires an integer or anything that can safely be casted to an integer
$validator->validate($value, new Type(array('type' => 'int', 'strict' => false))); |
@webmozart I'd be happy with whatever other solution you come up with. I just solved a problem I had and decided to share it with others. |
+1 for strict parameter. the same also for float, numeric etc. ;-) |
Replaced by #12312. |
Who would think it's so hard to write a validator for an integer that works with both
int
andstring
types like1
and'1'
. That's why I decided to add this validator to the core.