-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Improve support for optional/required fields in Collection constraint #3118
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
@@ -62,7 +68,7 @@ public function isValid($value, Constraint $constraint) | |||
} | |||
|
|||
unset($extraFields[$field]); | |||
} else { | |||
} else if (!$fieldConstraint instanceof Optional) { |
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.
should be elseif
without space
@bschussek I've rewritten a lot of test code for Collection validator in 2.0 branch and also had modified validator itself, as it had a bug #3078, consider waiting with this PR till fabpot will merge 2.0 back into master, as there will be code conflicts :) |
Does it helps to #2615 ? |
@canni: I've just merged 2.0 into master. |
…ince these two are new.
… test code duplication
Commits ------- e6e3da5 [Validator] Improved test coverage of CollectionValidator and reduced test code duplication 509c7bf [Validator] Moved Optional and Required constraints to dedicated sub namespace. bf59018 [Validator] Removed @api-tag from Optional and Required constraint, since these two are new. 6641f3e [Validator] Added constraints Optional and Required for the CollectionValidator Discussion ---------- [Validator] Improve support for optional/required fields in Collection constraint Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: none Todo: none  Improves the `Collection` constraint to test on a more granular level if entries of the collection are optional or required. Before this could only be set using the "allowExtraFields" and "allowMissingFields" options, but these are very general and limited. The former syntax - without Optional or Required - is still supported. Usage: $array = array( 'name' => 'Bernhard', 'birthdate' => '1970-01-01', ); $validator->validate($array, null, new Collection(array( 'name' => new Required(), 'birthdate' => new Optional(), )); // you can also pass additional constraints for the fields $validator->validate($array, null, new Collection(array( 'name' => new Required(array( new Type('string'), new MinLength(3), )), 'birthdate' => new Optional(new Date()), )); --------------------------------------------------------------------------- by canni at 2012-01-15T20:22:17Z @bschussek I've rewritten a lot of test code for Collection validator in 2.0 branch and also had modified validator itself, as it had a bug #3078, consider waiting with this PR till fabpot will merge 2.0 back into master, as there will be code conflicts :) --------------------------------------------------------------------------- by Koc at 2012-01-15T23:13:04Z Does it helps to #2615 ? --------------------------------------------------------------------------- by fabpot at 2012-01-16T06:44:53Z @canni: I've just merged 2.0 into master. --------------------------------------------------------------------------- by bschussek at 2012-01-16T12:05:19Z @fabpot: Rebased. I also fixed the CS issues mentioned by @stof.
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: none
Todo: none
Improves the
Collection
constraint to test on a more granular level if entries of the collection are optional or required. Before this could only be set using the "allowExtraFields" and "allowMissingFields" options, but these are very general and limited.The former syntax - without Optional or Required - is still supported.
Usage: