Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Aug 5, 2014

Conversation

webmozart
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #4453
License MIT
Doc PR -

With this PR, it finally becomes possible to set the groups of nested constraints in All and Collection:

/**
 * @Assert\Collection({
 *     "foo" = @Assert\NotNull(groups = "Strict"),
 *     "bar" = @Assert\NotBlank(groups = "Regular"),
 * })
 */
private $attr;

The group logic is implemented as described in this comment.

This PR supports the implementation of #9888 which should now become fairly simple.

@raziel057
Copy link
Contributor

+1 Thanks for your involvement. The form & validation components are very powerful!

@fabpot
Copy link
Member

fabpot commented Aug 4, 2014

👍

@webmozart
Copy link
Contributor Author

@Tobion What's your opinion on this PR?

@@ -49,11 +51,6 @@
const PROPERTY_CONSTRAINT = 'property';

/**
* @var array
*/
public $groups = array(self::DEFAULT_GROUP);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@Tobion
Copy link
Contributor

Tobion commented Aug 5, 2014

Needs a rebase because it conflicts with the new 2.5 constrait validation adding. Otherwise looks ok to me.

@webmozart
Copy link
Contributor Author

Rebased.

@stof
Copy link
Member

stof commented Aug 5, 2014

👍

1 similar comment
@Tobion
Copy link
Contributor

Tobion commented Aug 5, 2014

👍

webmozart added a commit to webmozart/symfony that referenced this pull request Aug 5, 2014
…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
@webmozart webmozart merged commit f6c070d into symfony:master Aug 5, 2014
@craue
Copy link
Contributor

craue commented Aug 6, 2014

I've got some failing tests because of this PR, but don't know why yet. Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants