Skip to content

[Validator] Add a constraint to sequentially validate a set of constraints #13206

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

Conversation

ogizanagi
Copy link
Contributor

closes #13076

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Looks really good, thanks. Just some minor comments

@ogizanagi ogizanagi force-pushed the validator-sequentially-constraint branch 2 times, most recently from bc09631 to fdd9bad Compare February 22, 2020 15:25
@ogizanagi
Copy link
Contributor Author

I've applied your suggestions, thank you 👍

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Another round :)

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Nice! Thanks

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

👍🏻

* @Assert\NotBlank(),
* @Assert\Type("string"),
* @Assert\Length(min=10),
* @Assert\Regex(Place::ADDRESS_REGEX),
Copy link
Contributor

@OskarStark OskarStark Feb 23, 2020

Choose a reason for hiding this comment

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

One minor, do you have a regex pattern which can be added? Do we really need the regex here? If yes, should we add the constant to the code example?

But adding a regex is maybe distracting, could we inline the pattern or is it anyway to complex?

What do you think of removing it completely from the example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to avoid adding a regex pattern. I used (but didn't show) a constant for the reason mentioned: the regex isn't important on its own and would be distracting.
I think the @Regex in the example deserve a purpose to demonstrate the step-by-step application of the rules, as it'll usually fail hard despite being used conjointly with Type without the Sequential constraint. But @Length demonstrate the same, so if you really prefer, I can remove it indeed.

@OskarStark
Copy link
Contributor

Thank you Maxime.

@OskarStark OskarStark merged commit b78e05a into symfony:master Feb 24, 2020
@ogizanagi ogizanagi deleted the validator-sequentially-constraint branch February 24, 2020 10:06
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Feb 25, 2020
…+ target guards (ogizanagi)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Validator] Allow Sequentially constraints on classes + target guards

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | todo in symfony/symfony-docs#13206 if not merged yet

There is no reason to limit this constraint to properties, so let's add classes as targets.

Additionally, let's ensure embedded constraints matches allowed targets too.

Commits
-------

1e02a96 [Validator] Allow Sequentially constraints on classes
symfony-splitter pushed a commit to symfony/validator that referenced this pull request Feb 25, 2020
…+ target guards (ogizanagi)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Validator] Allow Sequentially constraints on classes + target guards

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | todo in symfony/symfony-docs#13206 if not merged yet

There is no reason to limit this constraint to properties, so let's add classes as targets.

Additionally, let's ensure embedded constraints matches allowed targets too.

Commits
-------

1e02a96286 [Validator] Allow Sequentially constraints on classes
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.

[Validator] Add a constraint to sequentially validate a set of constrai…
4 participants