@@ -102,13 +102,7 @@ The specification is an array of key => filter specification pairs.
102102The 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
103103may 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
113107The rest of the specification for the field are the filters to apply.
114108
@@ -122,6 +116,259 @@ of the final filter is set in the result array.
122116
123117The example above should help clarify all this.
124118
119+ # Filterer Options
120+
121+ ## allowUnknowns
122+
123+ #### Summary
124+
125+ Flag to allow elements in unfiltered input that are not present in the filterer specification.
126+
127+ #### Types
128+
129+ * bool
130+
131+ #### Default
132+
133+ The default value is ` false `
134+
135+ #### Constant
136+
137+ ``` php
138+ TraderInteractive\FiltererOptions::ALLOW_UNKNOWNS
139+ ```
140+
141+ #### Example
142+
143+ ``` php
144+ $options = [
145+ TraderInteractive\FiltererOptions::ALLOW_UNKNOWNS => true,
146+ ];
147+
148+ $filterer = new TraderInteractive\Filterer($specification, $options);
149+ ```
150+
151+ ## defaultRequired
152+
153+ #### Summary
154+
155+ Flag for the default required behavior of all elements in the filterer specification. If ` true ` all elements in the specification are required unless they have the required filter option set.
156+
157+ #### Types
158+
159+ * bool
160+
161+ #### Default
162+
163+ The default value is ` false `
164+
165+ #### Constant
166+
167+ ``` php
168+ TraderInteractive\FiltererOptions::DEFAULT_REQUIRED
169+ ```
170+
171+ #### Example
172+
173+ ``` php
174+ $options = [
175+ TraderInteractive\FiltererOptions::DEFAULT_REQUIRED => true,
176+ ];
177+
178+ $filterer = new TraderInteractive\Filterer($specification, $options);
179+ ```
180+
181+ ## responseType
182+
183+ #### Summary
184+
185+ Specifies the type of response which The Filterer::filter method will return. It can be ` array ` or ` \TraderInteractive\FilterResponse `
186+
187+ #### Types
188+
189+ * string
190+
191+ #### Default
192+
193+ The default value is ` array `
194+
195+ #### Constant
196+
197+ ``` php
198+ TraderInteractive\FiltererOptions::RESPONSE_TYPE
199+ ```
200+
201+ #### Example
202+
203+ ``` php
204+ $options = [
205+ TraderInteractive\FiltererOptions::RESPONSE_TYPE => \TraderInteractive\FilterResponse::class,
206+ ];
207+
208+ $filterer = new TraderInteractive\Filterer($specification, $options);
209+ ```
210+ # Filter Options
211+
212+ ## required
213+
214+ #### Summary
215+
216+ Defines whether this field is a required element of the array. This value overrides the global filter specification's ` defaultRequired ` option.
217+
218+ #### Types
219+
220+ * bool
221+
222+ #### Default
223+
224+ The default value depends on the ` defaultRequired ` Filterer Option.
225+
226+ #### Constant
227+
228+ ``` php
229+ TraderInteractive\FilterOptions::IS_REQUIRED
230+ ```
231+
232+ #### Example
233+
234+ ``` php
235+ $specificaton = [
236+ 'id' => [TraderInteractive\FilterOptions::IS_REQUIRED => true, ['uint']],
237+ ];
238+ ```
239+
240+ ## default
241+
242+ #### Summary
243+
244+ 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.
245+
246+ #### Types
247+ * string
248+
249+ #### Default
250+
251+ There is no default value for this option.
252+
253+ #### Constant
254+
255+ ``` php
256+ TraderInteractive\FilterOptions::DEFAULT_VALUE
257+ ```
258+
259+ #### Example
260+ ``` php
261+ $specificaton = [
262+ 'subscribe' => [TraderInteractive\FilterOptions::DEFAULT_VALUE => true, ['bool']],
263+ 'status' => [TraderInteractive\FilterOptions::DEFAULT_VALUE => 'A', ['string', false, 1, 1]],
264+ ];
265+ ```
266+
267+ ## error
268+
269+ #### Summary
270+
271+ 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.
272+
273+ #### Types
274+
275+ * string
276+
277+ #### Default
278+
279+ There is no default value for this option.
280+
281+ #### Constant
282+
283+ ``` php
284+ TraderInteractive\FilterOptions::CUSTOM_ERROR
285+ ```
286+
287+ #### Example
288+
289+ ``` php
290+ $specificaton = [
291+ 'price' => [
292+ TraderInteractive\FilterOptions::CUSTOM_ERROR => 'Price {value} was not between 0 and 100',
293+ ['uint', false, 0, 100],
294+ ],
295+ ];
296+ ```
297+
298+ ## conflictsWith
299+
300+ #### Summary
301+
302+ 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.
303+
304+ #### Types
305+
306+ * string
307+
308+ #### Default
309+
310+ There is no default value for this option.
311+
312+ #### Constant
313+
314+ ``` php
315+ TraderInteractive\FilterOptions::CONFLICTS_WITH
316+ ```
317+
318+ #### Example
319+
320+ ``` php
321+ $specification = [
322+ 'id' => [
323+ TraderInteractive\FilterOptions::CONFLICTS_WITH => 'code',
324+ [['uint']],
325+ ],
326+ 'code' => [
327+ TraderInteractive\FilterOptions::CONFLICTS_WITH => 'id',
328+ [['string']],
329+ ],
330+ ];
331+ ```
332+
333+ ## uses
334+
335+ #### Summary
336+
337+ Specifies an array of input values that should be used as part of a field's filter specification.
338+
339+ #### Types
340+
341+ * string[ ]
342+
343+ #### Default
344+
345+ The default value for this option is an empty array.
346+
347+ #### Constant
348+
349+ ``` php
350+ TraderInteractive\FilterOptions::USES
351+ ```
352+
353+ #### Example
354+
355+ ``` php
356+ $specification = [
357+ 'base' => [
358+ [['float']],
359+ ],
360+ 'exponent' => [
361+ ['uint'],
362+ [
363+ TraderInteractive\FilterOptions::USES => 'base',
364+ 'pow',
365+ ],
366+ ],
367+ ];
368+ ```
369+
370+ The exponent filter spec will call the PHP function ` pow() ` with the value provided and the result of the filtered ` base `
371+
125372### Included Filters
126373Of course, any function can potentially be used as a filter, but we include some useful filters with aliases for common circumstances.
127374
@@ -296,13 +543,13 @@ The following checks that `$value` is a timezone
296543$timezone = \TraderInteractive\Filter\DateTimeZone::filter('America/New_York');
297544```
298545
299- ##Contact
546+ ## Contact
300547Developers may be contacted at:
301548
302549 * [ Pull Requests] ( https://github.com/traderinteractive/filter-php/pulls )
303550 * [ Issues] ( https://github.com/traderinteractive/filter-php/issues )
304551
305- ##Project Build
552+ ## Project Build
306553With a checkout of the code get [ Composer] ( http://getcomposer.org ) in your PATH and run:
307554
308555``` bash
0 commit comments