Commit ce145cd
committed
feature #42593 [Validator] Add the
This PR was merged into the 6.2 branch.
Discussion
----------
[Validator] Add the `When` constraint and validator
| Q | A
| ------------- | ---
| Branch? | 6.2
| Bug fix? | no
| New feature? | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| License | MIT
| Doc PR | symfony/symfony-docs#15722
This constraint allows you to apply constraints validation only if the provided condition is matched.
Usage:
```php
namespace App\Model;
use Symfony\Component\Validator\Constraints as Assert;
class Discount
{
private $type; // 'percent' or 'absolute'
/**
* `@Assert`\GreaterThan(0)
* `@Assert`\When(
* expression="this.type == 'percent'",
* constraints={`@LessThan`(100, message="The value should be between 0 and 100!")}
* )
*/
private $value;
// ...
}
```
See the documentation for details.
Commits
-------
9b7bdc9b18 [Validator] Add the When constraint and validatorWhen constraint and validator (wuchen90)File tree
2 files changed
+12
-0
lines changed- DependencyInjection
- Resources/config
2 files changed
+12
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
| |||
1571 | 1572 | | |
1572 | 1573 | | |
1573 | 1574 | | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
1574 | 1579 | | |
1575 | 1580 | | |
1576 | 1581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
| |||
0 commit comments