You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #31511 [Validator] Allow to use property paths to get limits in range constraint (Lctrs)
This PR was squashed before being merged into the 4.4 branch (closes #31511).
Discussion
----------
[Validator] Allow to use property paths to get limits in range constraint
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | Part of #31503
| License | MIT
| Doc PR | symfony/symfony-docs#11793
Similar as #22576, but for the `Range` constraint.
Commits
-------
2b509904c8 [Validator] Allow to use property paths to get limits in range constraint
@@ -36,14 +39,30 @@ class Range extends Constraint
36
39
public$maxMessage = 'This value should be {{ limit }} or less.';
37
40
public$invalidMessage = 'This value should be a valid number.';
38
41
public$min;
42
+
public$minPropertyPath;
39
43
public$max;
44
+
public$maxPropertyPath;
40
45
41
46
publicfunction__construct($options = null)
42
47
{
48
+
if (\is_array($options)) {
49
+
if (isset($options['min']) && isset($options['minPropertyPath'])) {
50
+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint requires only one of the "min" or "minPropertyPath" options to be set, not both.', \get_class($this)));
51
+
}
52
+
53
+
if (isset($options['max']) && isset($options['maxPropertyPath'])) {
54
+
thrownewConstraintDefinitionException(sprintf('The "%s" constraint requires only one of the "max" or "maxPropertyPath" options to be set, not both.', \get_class($this)));
55
+
}
56
+
57
+
if ((isset($options['minPropertyPath']) || isset($options['maxPropertyPath'])) && !class_exists(PropertyAccess::class)) {
58
+
thrownewLogicException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "minPropertyPath" or "maxPropertyPath" option.', \get_class($this)));
59
+
}
60
+
}
61
+
43
62
parent::__construct($options);
44
63
45
-
if (null === $this->min && null === $this->max) {
46
-
thrownewMissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), ['min', 'max']);
thrownewMissingOptionsException(sprintf('Either option "min", "minPropertyPath", "max" or "maxPropertyPath" must be given for constraint %s', __CLASS__), ['min', 'max']);
0 commit comments