particle/filter

Flexible and highly usable filter library with no dependencies.

v1.5.2 2019-08-19 15:19 UTC

README

Travis-CI Packagist Packagist downloads Scrutinizer Scrutinizer

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