@@ -20,9 +20,13 @@ final class Enum extends Choice
20
20
*/
21
21
public $ enum ;
22
22
23
+ /**
24
+ * @param array<string, mixed> $options
25
+ */
23
26
public function __construct (
24
- $ enum = null ,
25
- $ callback = null ,
27
+ array $ options = [],
28
+ string |null $ enum = null ,
29
+ callable |null |string $ callback = null ,
26
30
bool $ multiple = null ,
27
31
bool $ strict = null ,
28
32
int $ min = null ,
@@ -31,57 +35,29 @@ public function __construct(
31
35
string $ multipleMessage = null ,
32
36
string $ minMessage = null ,
33
37
string $ maxMessage = null ,
34
- $ groups = null ,
35
- $ payload = null ,
36
- array $ options = []
38
+ array |null $ groups = null ,
39
+ mixed $ payload = null ,
37
40
) {
38
- if (\is_array ($ enum )) {
39
- // Symfony 4.4 Constraints has single constructor argument containing all options
40
- parent ::__construct ($ enum );
41
- } else {
42
- if (\is_string ($ enum )) {
43
- $ this ->enum = $ enum ;
44
- }
45
- // Symfony 5.x Constraints has many constructor arguments for PHP 8.0 Attributes support
46
-
47
- $ firstConstructorArg = (new \ReflectionClass (Choice::class))
48
- ->getConstructor ()->getParameters ()[0 ]->getName ();
49
- if ($ firstConstructorArg === 'choices ' ) {
50
- // Prior to Symfony 5.3, first argument of Choice was $choices
51
- parent ::__construct (
52
- null ,
53
- $ callback ,
54
- $ multiple ,
55
- $ strict ,
56
- $ min ,
57
- $ max ,
58
- $ message ,
59
- $ multipleMessage ,
60
- $ minMessage ,
61
- $ maxMessage ,
62
- $ groups ,
63
- $ payload ,
64
- $ options
65
- );
66
- } else {
67
- // Since Symfony 5.3, first argument of Choice is $options
68
- parent ::__construct (
69
- $ options ,
70
- null ,
71
- $ callback ,
72
- $ multiple ,
73
- $ strict ,
74
- $ min ,
75
- $ max ,
76
- $ message ,
77
- $ multipleMessage ,
78
- $ minMessage ,
79
- $ maxMessage ,
80
- $ groups ,
81
- $ payload
82
- );
83
- }
41
+ if (\is_string ($ enum )) {
42
+ $ this ->enum = $ enum ;
84
43
}
44
+
45
+ // Since Symfony 5.3, first argument of Choice is $options
46
+ parent ::__construct (
47
+ $ options ,
48
+ null ,
49
+ $ callback ,
50
+ $ multiple ,
51
+ $ strict ,
52
+ $ min ,
53
+ $ max ,
54
+ $ message ,
55
+ $ multipleMessage ,
56
+ $ minMessage ,
57
+ $ maxMessage ,
58
+ $ groups ,
59
+ $ payload
60
+ );
85
61
}
86
62
87
63
public function getDefaultOption (): string
0 commit comments