@@ -137,26 +137,26 @@ $value = $member
137
137
138
138
### Validating the Item parameters.
139
139
140
- ### Checking for allowed keys
140
+ ### Checking for allowed names
141
141
142
142
Before validating the content of the ` Parameters ` container we need to make
143
- sure the container contains the proper data. That all the allowed keys are
144
- present. To do so we can use the ` Parameters::allowedKeys ` method. This
145
- method expects a list of keys . If other keys not present in the
143
+ sure the container contains the proper data. That all the allowed names are
144
+ present. To do so we can use the ` Parameters::allowedNames ` method. This
145
+ method expects a list of names . If other names not present in the
146
146
list are found in the container the method will return ` false ` . If we
147
- go back to our definition. We know that the allowed parameters keys attached
147
+ go back to our definition. We know that the allowed parameters names attached
148
148
to the item are: ` location ` , ` longitude ` , ` latitude ` and ` date `
149
149
150
150
``` php
151
151
use Bakame\Http\StructuredFields\Validation\Violation;
152
152
153
- if (!$member->parameters()->allowedKeys (['location', 'longitude', 'latitude', 'date'])) {
154
- throw new Violation('The parameters contains extra keys that are not allowed.');
153
+ if (!$member->parameters()->allowedNames (['location', 'longitude', 'latitude', 'date'])) {
154
+ throw new Violation('The parameters contains extra names that are not allowed.');
155
155
}
156
156
```
157
157
158
158
> [ !TIP]
159
- > The ` Dictionary ` class also exposes an ` allowedKeys ` method which behave the same way.
159
+ > The ` Dictionary ` class also exposes an ` allowedNames ` method which behave the same way.
160
160
161
161
> [ !WARNING]
162
162
> if the parameters container is empty no error will be triggered
@@ -208,13 +208,13 @@ all the criteria.
208
208
Going back to the HTTP field definitions we can translate the requirements and create the
209
209
following ` ParametersValidator ` .
210
210
211
- We need to make sure about the allowed keys for that. the class has a ` filterByCriteria ` which
211
+ We need to make sure about the allowed names for that. the class has a ` filterByCriteria ` which
212
212
expects the ` Parameters ` container as its sole argument.
213
213
214
214
``` php
215
215
$parametersValidator = ParametersValidator::new()
216
216
->filterByCriteria(function (Parameters $parameters): bool|string {
217
- return $parameters->allowedKeys (['location', 'longitude', 'latitude', 'date']);
217
+ return $parameters->allowedNames (['location', 'longitude', 'latitude', 'date']);
218
218
});
219
219
```
220
220
@@ -228,7 +228,7 @@ we did earlier we end up with the following entries.
228
228
``` php
229
229
use Bakame\Http\StructuredFields\Type;
230
230
231
- $parametersValidator = ->filterByKeys ([
231
+ $parametersValidator = ->filterByNames ([
232
232
'longitude' => [
233
233
'validate' => function (mixed $value) {
234
234
if (!Type::Decimal->supports($value)) {
@@ -242,7 +242,7 @@ $parametersValidator = ->filterByKeys([
242
242
]);
243
243
```
244
244
245
- We can do the same for all the other keys , the available parameters are:
245
+ We can do the same for all the other names , the available parameters are:
246
246
- ` validate ` : the callback used for validation; ` null ` by default
247
247
- ` required ` : a boolean telling whether the parameter presence is required; ` false ` by default
248
248
- ` default ` : the default value if the parameter is optional; ` null ` by default.
@@ -329,7 +329,7 @@ if ($validation->isSucces()) {
329
329
> [ !NOTE]
330
330
> If we only use the ` filterByCriteria ` method the full parameter data is returned.
331
331
332
- A ` filterByIndices ` method exists and behave exactly as the ` filterByKeys ` method.
332
+ A ` filterByIndices ` method exists and behave exactly as the ` filterByNames ` method.
333
333
There are two differences when it is used:
334
334
335
335
- The callback parameters are different (they match those of ` parameterByIndex ` )
0 commit comments