@@ -6,12 +6,12 @@ Validates that a value (or multiple values) exist in a given set of choices.
66Choice(
77 array $constraints,
88 bool $multiple = false,
9- ?int $minConstraint = null,
10- ?int $maxConstraint = null,
9+ ?int $min = null,
10+ ?int $max = null,
1111 string $message = 'The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.',
1212 string $multipleMessage = 'The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.',
13- string $minMessage = 'The {{ name }} value must have at least {{ minConstraint }} choices, {{ numValues }} choices given.',
14- string $maxMessage = 'The {{ name }} value must have at most {{ maxConstraint }} choices, {{ numValues }} choices given.'
13+ string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.',
14+ string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.'
1515);
1616```
1717
@@ -27,23 +27,23 @@ Validator::choice(['red', 'green', 'blue'], multiple: true)->validate(['red', 'b
2727Validator::choice(['red', 'green', 'blue'], multiple: true)->validate(['red', 'yellow']); // false;
2828
2929// Multiple with minimum number of choices
30- Validator::choice(['red', 'green', 'blue'], multiple: true, minConstraint : 2)->validate(['red', 'blue']); // true
31- Validator::choice(['red', 'green', 'blue'], multiple: true, minConstraint : 2)->validate(['red']); // false
30+ Validator::choice(['red', 'green', 'blue'], multiple: true, min : 2)->validate(['red', 'blue']); // true
31+ Validator::choice(['red', 'green', 'blue'], multiple: true, min : 2)->validate(['red']); // false
3232
3333// Multiple with maximum number of choices
34- Validator::choice(['red', 'green', 'blue'], multiple: true, maxConstraint : 2)->validate(['red', 'blue']); // true
35- Validator::choice(['red', 'green', 'blue'], multiple: true, maxConstraint : 2)->validate(['red', 'green', 'blue']); // false
34+ Validator::choice(['red', 'green', 'blue'], multiple: true, max : 2)->validate(['red', 'blue']); // true
35+ Validator::choice(['red', 'green', 'blue'], multiple: true, max : 2)->validate(['red', 'green', 'blue']); // false
3636
3737// Multiple with minimum and maximum number of choices
38- Validator::choice(['red', 'green', 'blue'], multiple: true, minConstraint : 2, maxConstraint : 3)->validate(['red', 'blue']); // true
39- Validator::choice(['red', 'green', 'blue'], multiple: true, minConstraint : 2, maxConstraint : 3)->validate(['red']); // false
38+ Validator::choice(['red', 'green', 'blue'], multiple: true, min : 2, max : 3)->validate(['red', 'blue']); // true
39+ Validator::choice(['red', 'green', 'blue'], multiple: true, min : 2, max : 3)->validate(['red']); // false
4040```
4141
4242> [ !NOTE]
4343> An ` UnexpectedValueException ` will be thrown when ` multiple ` is ` true ` and the input value is not an ` array ` .
4444
4545> [ !NOTE]
46- > An ` UnexpectedValueException ` will be thrown when the ` minConstraint ` value is greater than or equal to the ` maxConstraint ` value.
46+ > An ` UnexpectedValueException ` will be thrown when the ` min ` value is greater than or equal to the ` max ` value.
4747
4848## Options
4949
@@ -60,21 +60,21 @@ type: `bool` default: `false`
6060If this option is ` true ` , validation against an ` array ` of input values is enabled.
6161Each element of the input array must be a valid choice, otherwise it will fail.
6262
63- ### ` minConstraint `
63+ ### ` min `
6464
6565type: ` ?int ` default: ` null `
6666
6767If ` multiple ` is ` true ` , set a minimum number of input values to be required.
6868
69- For example, if ` minConstraint ` is 2, the input array must have at least 2 values.
69+ For example, if ` min ` is 2, the input array must have at least 2 values.
7070
71- ### ` maxConstraint `
71+ ### ` max `
7272
7373type: ` ?int ` default: ` null `
7474
7575If ` multiple ` is ` true ` , set a maximum number of input values to be required.
7676
77- For example, if ` maxConstraint ` is 2, the input array must have at most 2 values.
77+ For example, if ` max ` is 2, the input array must have at most 2 values.
7878
7979### ` message `
8080
@@ -106,37 +106,37 @@ The following parameters are available:
106106
107107### ` minMessage `
108108
109- type: ` string ` default: ` The {{ name }} value must have at least {{ minConstraint }} choices, {{ numValues }} choices given. `
109+ type: ` string ` default: ` The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given. `
110110
111- Message that will be shown when ` multiple ` is ` true ` and input array has fewer values than the defined in ` minConstraint ` .
111+ Message that will be shown when ` multiple ` is ` true ` and input array has fewer values than the defined in ` min ` .
112112
113113The following parameters are available:
114114
115- | Parameter | Description |
116- | ----------------------- | --------------------------------------|
117- | ` {{ value }} ` | The current invalid value |
118- | ` {{ numValues }} ` | The current invalid number of values |
119- | ` {{ name }} ` | Name of the invalid value |
120- | ` {{ constraints }} ` | The array of valid choices |
121- | ` {{ minConstraint }} ` | The minimum number of valid choices |
122- | ` {{ maxConstraint }} ` | The maximum number of valid choices |
115+ | Parameter | Description |
116+ | ---------------------| -- --------------------------------------|
117+ | ` {{ value }} ` | The current invalid value |
118+ | ` {{ name }} ` | Name of the invalid value |
119+ | ` {{ constraints }} ` | The array of valid choices |
120+ | ` {{ min }} ` | The minimum number of valid choices |
121+ | ` {{ max }} ` | The maximum number of valid choices |
122+ | ` {{ numElements }} ` | The current invalid number of elements |
123123
124124### ` maxMessage `
125125
126- type: ` string ` default: ` The {{ name }} value must have at most {{ maxConstraint }} choices, {{ numValues }} choices given. `
126+ type: ` string ` default: ` The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given. `
127127
128- Message that will be shown when ` multiple ` is ` true ` and input array has more values than the defined in ` maxConstraint ` .
128+ Message that will be shown when ` multiple ` is ` true ` and input array has more values than the defined in ` max ` .
129129
130130The following parameters are available:
131131
132- | Parameter | Description |
133- | ----------------------- | --------------------------------------|
134- | ` {{ value }} ` | The current invalid value |
135- | ` {{ numValues }} ` | The current invalid number of values |
136- | ` {{ name }} ` | Name of the invalid value |
137- | ` {{ constraints }} ` | The array of valid choices |
138- | ` {{ minConstraint }} ` | The minimum number of valid choices |
139- | ` {{ maxConstraint }} ` | The maximum number of valid choices |
132+ | Parameter | Description |
133+ | ---------------------| -- --------------------------------------|
134+ | ` {{ value }} ` | The current invalid value |
135+ | ` {{ name }} ` | Name of the invalid value |
136+ | ` {{ constraints }} ` | The array of valid choices |
137+ | ` {{ min }} ` | The minimum number of valid choices |
138+ | ` {{ max }} ` | The maximum number of valid choices |
139+ | ` {{ numElements }} ` | The current invalid number of elements |
140140
141141## Changelog
142142
0 commit comments