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
Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Composite.php
+64-42Lines changed: 64 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -55,57 +55,63 @@ public function __construct(mixed $options = null, ?array $groups = null, mixed
55
55
56
56
$this->initializeNestedConstraints();
57
57
58
-
/* @var Constraint[] $nestedConstraints */
59
-
$compositeOption = $this->getCompositeOption();
60
-
$nestedConstraints = $this->$compositeOption;
61
-
62
-
if (!\is_array($nestedConstraints)) {
63
-
$nestedConstraints = [$nestedConstraints];
58
+
$compositeOptions = $this->getCompositeOption();
59
+
if (!\is_array($compositeOptions)) {
60
+
$compositeOptions = [$compositeOptions];
64
61
}
65
62
66
-
foreach ($nestedConstraintsas$constraint) {
67
-
if (!$constraintinstanceof Constraint) {
68
-
if (\is_object($constraint)) {
69
-
$constraint = $constraint::class;
70
-
}
63
+
foreach ($compositeOptionsas$compositeOption) {
64
+
/* @var Constraint[] $nestedConstraints */
65
+
$nestedConstraints = $this->$compositeOption;
71
66
72
-
thrownewConstraintDefinitionException(\sprintf('The value "%s" is not an instance of Constraint in constraint "%s".', $constraint, static::class));
67
+
if (!\is_array($nestedConstraints)) {
68
+
$nestedConstraints = [$nestedConstraints];
73
69
}
74
70
75
-
if ($constraintinstanceof Valid) {
76
-
thrownewConstraintDefinitionException(\sprintf('The constraint Valid cannot be nested inside constraint "%s". You can only declare the Valid constraint directly on a field or method.', static::class));
77
-
}
78
-
}
71
+
foreach ($nestedConstraintsas$constraint) {
72
+
if (!$constraintinstanceof Constraint) {
73
+
if (\is_object($constraint)) {
74
+
$constraint = $constraint::class;
75
+
}
79
76
80
-
if (!isset(((array) $this)['groups'])) {
81
-
$mergedGroups = [];
77
+
thrownewConstraintDefinitionException(\sprintf('The value "%s" is not an instance of Constraint in constraint "%s".', $constraint, static::class));
78
+
}
82
79
83
-
foreach ($nestedConstraintsas$constraint) {
84
-
foreach ($constraint->groupsas$group) {
85
-
$mergedGroups[$group] = true;
80
+
if ($constraintinstanceof Valid) {
81
+
thrownewConstraintDefinitionException(\sprintf('The constraint Valid cannot be nested inside constraint "%s". You can only declare the Valid constraint directly on a field or method.', static::class));
86
82
}
87
83
}
88
84
89
-
// prevent empty composite constraint to have empty groups
thrownewConstraintDefinitionException(\sprintf('The group(s) "%s" passed to the constraint "%s" should also be passed to its containing constraint "%s".', implode('", "', $excessGroups), get_debug_type($constraint), static::class));
thrownewConstraintDefinitionException(\sprintf('The group(s) "%s" passed to the constraint "%s" should also be passed to its containing constraint "%s".', implode('", "', $excessGroups), get_debug_type($constraint), static::class));
107
+
}
108
+
} else {
109
+
$constraint->groups = $this->groups;
102
110
}
103
-
} else {
104
-
$constraint->groups = $this->groups;
105
111
}
106
-
}
107
112
108
-
$this->$compositeOption = $nestedConstraints;
113
+
$this->$compositeOption = $nestedConstraints;
114
+
}
109
115
}
110
116
111
117
/**
@@ -115,18 +121,25 @@ public function addImplicitGroupName(string $group): void
thrownewLogicException(\sprintf('The "symfony/expression-language" component is required to use the "%s" constraint. Try running "composer require symfony/expression-language".', __CLASS__));
@@ -56,12 +58,17 @@ public function __construct(string|Expression|array $expression, array|Constrain
56
58
57
59
$options['expression'] = $expression;
58
60
$options['constraints'] = $constraints;
61
+
$options['otherwise'] = $otherwise;
59
62
}
60
63
61
64
if (isset($options['constraints']) && !\is_array($options['constraints'])) {
0 commit comments