zendframework/zf2 — pull request #6961 by gabrielsomoza (2014-12-05 15:58:15+00:00)
Title: Added WhitelistFilter

This new filter will behave either as a blacklist or a whitelist. If the value being filtered exists in the list of known values, the filter will return the value if its a whitelist or `null` if its a blacklist. The opposite will happen if value is not in the list.

### Whitelist
```php
$whitelist = new \Zend\Filter\Whitelist(array(
'list' => array('allowed-1', 'allowed-2')
));
echo $whitelist->filter('allowed-2'); // => 'allowed-2'
echo $whitelist->filter('not-allowed'); // => null
```

### Blacklist
```php
$blacklist = new \Zend\Filter\Whitelist(array(
'type' => 'blacklist', // optional, default is 'whitelist'
'list' => array('not-allowed-1', 'not-allowed-2')
));
echo $blacklist->filter('allowed'); // => 'allowed'
echo $blacklist->filter('not-allowed-2'); // => null
```

### Notes

1. Maybe calling the filter class `Whitelist` might be counter-intuitive if the desired behavior is that of a blacklist. But I couldn't think of a better way to name the filter - something like "AllowedList" would be a synonym of "whitelist" and something like "List" would just be too vague. Open to suggestions.
2. I decided to allow only one type of configuration in the constructor (by array of options) just to keep it simple. If you'd like to allow for a more dynamic constructor (like a few other filters do) let me know.

See #6960 for more info.