File tree 1 file changed +6
-2
lines changed
src/Symfony/Component/Validator/Constraints
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,11 @@ public function validate($value, Constraint $constraint)
35
35
throw new UnexpectedTypeException ($ constraint , Choice::class);
36
36
}
37
37
38
- if (!\is_array ($ constraint ->choices ) && !is_a ($ constraint ->choices , \BackedEnum::class, true ) && !$ constraint ->callback ) {
38
+ $ valid = \is_array ($ constraint ->choices )
39
+ || (\is_string ($ constraint ->choices ) && \is_a ($ constraint ->choices , \BackedEnum::class, true ))
40
+ || isset ($ constraint ->callback );
41
+
42
+ if (!$ valid ) {
39
43
throw new ConstraintDefinitionException ('Either "choices" or "callback" must be specified on constraint Choice. ' );
40
44
}
41
45
@@ -55,7 +59,7 @@ public function validate($value, Constraint $constraint)
55
59
throw new ConstraintDefinitionException ('The Choice constraint expects a valid callback. ' );
56
60
}
57
61
$ choices = $ choices ();
58
- } elseif (is_a ($ constraint ->choices , \BackedEnum::class, true )) {
62
+ } elseif (\ is_a ($ constraint ->choices , \BackedEnum::class, true )) {
59
63
$ choices = array_map (
60
64
function (\BackedEnum $ enum ) {
61
65
return $ enum ->value ;
You can’t perform that action at this time.
0 commit comments