Skip to content

Commit fcf0255

Browse files
committed
Add Section for Filter Options
1 parent 7bde2d0 commit fcf0255

1 file changed

Lines changed: 123 additions & 7 deletions

File tree

README.md

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,7 @@ The specification is an array of key => filter specification pairs.
102102
The keys define the known fields in the array. Any fields in the array that are not in the specification are treated as "unknown" fields and
103103
may cause validation to fail, depending on the value of the `allowUnknowns` option.
104104

105-
The filter specification for a single field is also an array. It can contain two special keys:
106-
* `required` defines whether this field is a required element of the array. This value overrides the global filter specification's
107-
`defaultRequired` option.
108-
* `default` defines what the default value of this field is if none is given. A field with a default value will be guaranteed to be in the
109-
result. The `required` value does not affect `default` behavior.
110-
* `error` defines a custom error message to be returned if the value fails filtering. Within the error string, `{value}` can be used as a placeholder
111-
for the value that failed filtering.
105+
The filter specification for a single field is also an array. It can contain predefined [filter options](#filter-options).
112106

113107
The rest of the specification for the field are the filters to apply.
114108

@@ -122,6 +116,128 @@ of the final filter is set in the result array.
122116

123117
The example above should help clarify all this.
124118

119+
# Filter Options
120+
121+
## required
122+
123+
#### Summary
124+
125+
Defines whether this field is a required element of the array. This value overrides the global filter specification's `defaultRequired` option.
126+
127+
#### Types
128+
129+
* bool
130+
131+
#### Default
132+
133+
The default value depends on the `defaultRequired` Filterer Option.
134+
135+
#### Constant
136+
137+
```php
138+
TraderInteractive\FilterOptions::IS_REQUIRED
139+
```
140+
141+
#### Example
142+
143+
```php
144+
$specificaton = [
145+
'id' => [TraderInteractive\FilterOptions::IS_REQUIRED => true, ['uint']],
146+
];
147+
```
148+
149+
## default
150+
151+
#### Summary
152+
153+
Defines what the default value of this field is if none is given. A field with a default value will be guaranteed to be in the result. The `required` value does not affect `default` behavior.
154+
155+
#### Types
156+
* string
157+
158+
#### Default
159+
160+
There is no default value for this option.
161+
162+
#### Constant
163+
164+
```php
165+
TraderInteractive\FilterOptions::DEFAULT_VALUE
166+
```
167+
168+
#### Example
169+
```php
170+
$specificaton = [
171+
'subscribe' => [TraderInteractive\FilterOptions::DEFAULT_VALUE => true, ['bool']],
172+
'status' => [TraderInteractive\FilterOptions::DEFAULT_VALUE => 'A', ['string', false, 1, 1]],
173+
];
174+
```
175+
176+
## error
177+
178+
#### Summary
179+
180+
Defines a custom error message to be returned if the value fails filtering. Within the error string, `{value}` can be used as a placeholder for the value that failed filtering.
181+
182+
#### Types
183+
184+
* string
185+
186+
#### Default
187+
188+
There is no default value for this option.
189+
190+
#### Constant
191+
192+
```php
193+
TraderInteractive\FilterOptions::CUSTOM_ERROR
194+
```
195+
196+
#### Example
197+
198+
```php
199+
$specificaton = [
200+
'price' => [
201+
TraderInteractive\FilterOptions::CUSTOM_ERROR => 'Price {value} was not between 0 and 100',
202+
['uint', false, 0, 100],
203+
],
204+
];
205+
```
206+
207+
## conflictsWith
208+
209+
#### Summary
210+
211+
Defines any input fields with which a given field will conflict. Used when one field can be given in input or another but not both.
212+
213+
#### Types
214+
215+
* string
216+
217+
#### Default
218+
219+
There is no default value for this option.
220+
221+
#### Constant
222+
223+
```php
224+
TraderInteractive\FilterOptions::CONFLICTS_WITH
225+
```
226+
227+
#### Example
228+
229+
```php
230+
$specification = [
231+
'id' => [
232+
TraderInteractive\FilterOptions::CONFLICTS_WITH => 'code',
233+
[['uint']],
234+
],
235+
'code' => [
236+
TraderInteractive\FilterOptions::CONFLICTS_WITH => 'id',
237+
[['string']],
238+
],
239+
];
240+
```
125241
### Included Filters
126242
Of course, any function can potentially be used as a filter, but we include some useful filters with aliases for common circumstances.
127243

0 commit comments

Comments
 (0)