particle / filter
Flexible and highly usable filter library with no dependencies.
Installs: 506 599
Dependents: 5
Suggesters: 0
Security: 0
Stars: 82
Watchers: 6
Forks: 11
Open Issues: 8
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: 2.*
README
Particle\Filter is a very small filtering library, with the easiest and most usable API we could possibly create.
Small usage example
$f = new Particle\Filter\Filter; $f->values(['user.first_name', 'user.last_name'])->trim()->lower()->upperFirst(); $f->value('newsletter')->bool(); $f->value('created_at')->defaults(date('Y-m-d')); $f->all()->removeNull(); $result = $f->filter([ 'user' => [ 'first_name' => ' JOHN ', 'middle_name' => null, 'last_name' => ' DOE ', ], 'newsletter' => 'yes', 'referral' => null, ]); var_dump($result); /** * array(3) { * ["user"]=> array(2) { * ["first_name"]=> string(4) "John" * ["last_name"]=> string(3) "Doe" * } * ["newsletter"]=> bool(true) * ["created_at"]=> string(10) "2015-12-10" * } */
Functional features
- Filter an array of values
- Get a cleaned array after filtering
- A large set of available filters
- Ability to set default values if nothing is provided
- Ability to filter nested, repeated arrays
- Ability to remove (empty) values
- Ability to extend the filter to add your own custom filter rules
Non functional features
- Easy to write (IDE auto-completion for easy development)
- Easy to read (improves peer review)
- Fully documented: filter.particle-php.com
- Fully tested: Scrutinizer
- Zero dependencies
===
Find more information and advanced usage examples at filter.particle-php.com