|
19 | 19 | * |
20 | 20 | * @author Bernhard Schussek <bschussek@gmail.com> |
21 | 21 | */ |
| 22 | +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] |
22 | 23 | class Choice extends Constraint |
23 | 24 | { |
24 | 25 | const NO_SUCH_CHOICE_ERROR = '8e179f1b-97aa-4560-a02f-2a8b42e49df7'; |
@@ -49,4 +50,38 @@ public function getDefaultOption() |
49 | 50 | { |
50 | 51 | return 'choices'; |
51 | 52 | } |
| 53 | + |
| 54 | + public function __construct( |
| 55 | + $choices = null, |
| 56 | + $callback = null, |
| 57 | + bool $multiple = null, |
| 58 | + bool $strict = null, |
| 59 | + int $min = null, |
| 60 | + int $max = null, |
| 61 | + string $message = null, |
| 62 | + string $multipleMessage = null, |
| 63 | + string $minMessage = null, |
| 64 | + string $maxMessage = null, |
| 65 | + $groups = null, |
| 66 | + $payload = null, |
| 67 | + array $options = [] |
| 68 | + ) { |
| 69 | + if (\is_array($choices) && \is_string(key($choices))) { |
| 70 | + $options = array_merge($choices, $options); |
| 71 | + } elseif (null !== $choices) { |
| 72 | + $options['choices'] = $choices; |
| 73 | + } |
| 74 | + |
| 75 | + parent::__construct($options, $groups, $payload); |
| 76 | + |
| 77 | + $this->callback = $callback ?? $this->callback; |
| 78 | + $this->multiple = $multiple ?? $this->multiple; |
| 79 | + $this->strict = $strict ?? $this->strict; |
| 80 | + $this->min = $min ?? $this->min; |
| 81 | + $this->max = $max ?? $this->max; |
| 82 | + $this->message = $message ?? $this->message; |
| 83 | + $this->multipleMessage = $multipleMessage ?? $this->multipleMessage; |
| 84 | + $this->minMessage = $minMessage ?? $this->minMessage; |
| 85 | + $this->maxMessage = $maxMessage ?? $this->maxMessage; |
| 86 | + } |
52 | 87 | } |
0 commit comments