Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions docs/book/standard-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,23 @@ and returns a `BOOLEAN` just as you would get by type casting to `BOOLEAN`.
Sometimes, casting with `(boolean)` will not suffice. `Zend\Filter\Boolean`
allows you to configure specific types to convert, as well as which to omit.

The following types can be handled:
The following types can be handled (in this precedence order):

- `boolean`: Returns a boolean value as is.
- `integer`: Converts an integer `0` value to `FALSE`.
- `float`: Converts a float `0.0` value to `FALSE`.
- `string`: Converts an empty string `''` to `FALSE`.
- `zero`: Converts a string containing the single character zero (`'0'`) to `FALSE`.
- `empty_array`: Converts an empty `array` to `FALSE`.
- `localized`: Converts any string as mapped (case sensitive) in the `translations` option.
- `false`: Converts a string equal to the word "false" (case insensitive) to boolean `FALSE`.
- `null`: Converts a `NULL` value to `FALSE`.
- `php`: Converts values according to PHP when casting them to `BOOLEAN`.
- `false_string`: Converts a string containing the word "false" to a boolean `FALSE`.
- `yes`: Converts a localized string which contains the word "no" to `FALSE`.
- `all`: Converts all above types to `BOOLEAN`.
- `array`: Converts an empty `array` to `FALSE`.
- `zero`: Converts a string to `FALSE` if it equates to `'0'` after type juggling.
- `string`: Converts an empty string `''` to `FALSE`.
- `float`: Converts a float `0.0` value to `FALSE`.
- `integer`: Converts an integer `0` value to `FALSE`.
- `boolean`: Returns a boolean value as is.

There are 2 additional special types:

- `all`: Converts all above types to `BOOLEAN`. The same as setting all above types.
- `php`: Converts all above types to `BOOLEAN` except `localized` or `false`. The same as setting all above types except `localized` or `false`.


All other given values will return `TRUE` by default.

Expand Down Expand Up @@ -239,7 +243,7 @@ This means that you can ask your customer in a form for "yes" or "no" within his
`Zend\Filter\Boolean` will convert the response to the appropriate boolean value.

To set the translation and the corresponding value, you can use the `translations` option or the
method `setTranslations`.
method `setTranslations`. The translations must be set for any values you wish to map to boolean values.

```php
$filter = new Zend\Filter\Boolean([
Expand Down Expand Up @@ -269,19 +273,18 @@ In this case `Zend\Filter\Boolean` will work as described in the following
table, which shows which values return `TRUE` or `FALSE`. All other given values
are returned without change when `casting` is set to `FALSE`

Type | True | False
---- | ---- | -----
`Zend\Filter\Boolean::TYPE_BOOLEAN` | `TRUE` | `FALSE`
`Zend\Filter\Boolean::TYPE_EMPTY_ARRAY` | `array()` |
`Zend\Filter\Boolean::TYPE_FALSE_STRING` | `"false"` (case insensitive) | `"true"` (case insensitive)
`Zend\Filter\Boolean::TYPE_FLOAT` | `0.0` | `1.0`
`Zend\Filter\Boolean::TYPE_INTEGER` | `0` | `1`
`Zend\Filter\Boolean::TYPE_LOCALIZED` | localized `"yes"` (case insensitive) | localized `"no"` (case insensitive)
`Zend\Filter\Boolean::TYPE_NULL` | `NULL` |
`Zend\Filter\Boolean::TYPE_STRING` | `""` |
`Zend\Filter\Boolean::TYPE_ZERO_STRING` | `"0"` | `"1"`

The following example shows the behaviour when changing the `casting` option:
Type Constant | Type String | True | False
---- | ---- | ---- | -----
`Zend\Filter\Boolean::TYPE_BOOLEAN` | `boolean` | `TRUE` | `FALSE`
`Zend\Filter\Boolean::TYPE_EMPTY_ARRAY` | `array` | | `[]`
`Zend\Filter\Boolean::TYPE_FALSE_STRING` | `false` | `'false'` (case insensitive) | `'true'` (case insensitive)
`Zend\Filter\Boolean::TYPE_FLOAT` | `float` | `1.0` | `0.0`
`Zend\Filter\Boolean::TYPE_INTEGER` | `integer` | `1` | `0`
`Zend\Filter\Boolean::TYPE_NULL` | `null` | | `NULL`
`Zend\Filter\Boolean::TYPE_STRING` | `string` | | `''`
`Zend\Filter\Boolean::TYPE_ZERO_STRING` | `zero` | `'1'` | `'0'`

The following example shows the behavior when changing the `casting` option:

```php
$filter = new Zend\Filter\Boolean([
Expand Down