Skip to content
Flexible and highly usable filtering library with no dependencies.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Move github specific files to a github folder Feb 23, 2016
docs Added a JSON decode filter (#58) Dec 13, 2017
src
tests Trim & Cut check string type (#64) Aug 19, 2019
.gitattributes Move github specific files to a github folder Feb 23, 2016
.gitignore Add composer May 22, 2015
.scrutinizer.yml Add scrutinizer exception and shorten namespace usage May 26, 2015
.travis.yml Remove unsupported PHP version from Travis Aug 19, 2019
LICENSE Some document changes May 22, 2015
README.md Merge branch 'feature/remove-keys' of github.com:RickvdStaaij/Filter … Jan 22, 2016
composer.json Update the license in composer.json so packagist will update again (#59) Jan 30, 2018
composer.lock Updating to php 5.4 at composer and updating composer lock to remove … Jun 2, 2015
mkdocs.yml Add documentation on multibyte encoding Jun 26, 2015
phpunit.xml Fix: Simplify test bootstrapping Jul 6, 2016

README.md

Particle\Filter

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

You can’t perform that action at this time.