-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Fixed group handling in composite constraints #11505
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
+1 Thanks for your involvement. The form & validation components are very powerful! |
👍 |
@Tobion What's your opinion on this PR? |
@@ -49,11 +51,6 @@ | |||
const PROPERTY_CONSTRAINT = 'property'; | |||
|
|||
/** | |||
* @var array | |||
*/ | |||
public $groups = array(self::DEFAULT_GROUP); |
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.
Not sure why this was changed. Makes it a little inconsistent between groups option and all the rest which are real properties.
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.
Because we need a way to determine whether the $groups
property was set (in that case it's not overridden by Composite constraints) or not (in that case the Composite constraint sets it). The alternative would be to store something like $providedOptions
, but that was even uglier:
- If we store
$providedOptions
in the serialized form of the constraints, the size of the serialized data grows unnecessarily. - If we don't, then the condition
$constraint == unserialize(serialize($constraint))
doesn't hold anymore, which breaks many tests.
So I went with this solution.
Needs a rebase because it conflicts with the new 2.5 constrait validation adding. Otherwise looks ok to me. |
Rebased. |
👍 |
1 similar comment
👍 |
…onstraints (webmozart) This PR was merged into the 2.6-dev branch. Discussion ---------- [Validator] Fixed group handling in composite constraints | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#4453 | License | MIT | Doc PR | - With this PR, it finally becomes possible to set the groups of nested constraints in All and Collection: ```php /** * @Assert\Collection({ * "foo" = @Assert\NotNull(groups = "Strict"), * "bar" = @Assert\NotBlank(groups = "Regular"), * }) */ private $attr; ``` The group logic is implemented as described in [this comment](symfony#4453 (comment)). This PR supports the implementation of symfony#9888 which should now become fairly simple. Commits ------- f6c070d [Validator] Fixed group handling in composite constraints
I've got some failing tests because of this PR, but don't know why yet. Any idea? |
With this PR, it finally becomes possible to set the groups of nested constraints in All and Collection:
The group logic is implemented as described in this comment.
This PR supports the implementation of #9888 which should now become fairly simple.