PHPackages                             jgswift/filtratr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jgswift/filtratr

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jgswift/filtratr
================

PHP 5.5+ filtering component

0.1.11(11y ago)321MITPHPPHP &gt;=5.5

Since Jan 19Pushed 11y ago2 watchersCompare

[ Source](https://github.com/jgswift/filtratr)[ Packagist](https://packagist.org/packages/jgswift/filtratr)[ RSS](/packages/jgswift-filtratr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

filtratr
========

[](#filtratr)

filtering &amp; mapping component

[![Build Status](https://camo.githubusercontent.com/53f1d27d2063e0519c59dbef0c1da2775d74db7ede6a53228b9b0a1c36500982/68747470733a2f2f7472617669732d63692e6f72672f6a6773776966742f66696c74726174722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jgswift/filtratr)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9501e7daa04a292d570cc5dc1b7454dfebfe33509ec29afddef5223bb8ddc230/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6773776966742f66696c74726174722f6261646765732f7175616c6974792d73636f72652e706e673f733d34633134333363643436383634343065306138613265623261306433616163396432613632333337)](https://scrutinizer-ci.com/g/jgswift/filtratr/)[![Latest Stable Version](https://camo.githubusercontent.com/887d65306b50cfab06aa57b026fcbd352b8b9dcb1e4d2bbd17cc2a9346503c0a/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f66696c74726174722f762f737461626c652e737667)](https://packagist.org/packages/jgswift/filtratr)[![License](https://camo.githubusercontent.com/d48eaa0cf1500ccc5b1b99e1d059394ed1411ff4864ec7fdce2d7e85954cf8e1/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f66696c74726174722f6c6963656e73652e737667)](https://packagist.org/packages/jgswift/filtratr)

Installation
------------

[](#installation)

Install via cli using [composer](https://getcomposer.org/):

```
php composer.phar require jgswift/filtratr:0.1.*
```

Install via composer.json using [composer](https://getcomposer.org/):

```
{
    "require": {
        "jgswift/filtratr": "0.1.*"
    }
}
```

Description
-----------

[](#description)

filtratr is an extensible lightweight filtering component that facilitates filtering and mapping of data structures. filtratr provides a functional programming interface and a fluid interface.

Dependency
----------

[](#dependency)

- php 5.5+
- [jgswift/qinq](http://github.com/jgswift/qinq) - quasi integrated query

Usage
-----

[](#usage)

### Filter

[](#filter)

Includes or excludes data from result depending on provided predicate. Predicates may be implemented functionally or through strings.

```
$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->filter('equals',['bar']);

var_dump($filter()); // ['foo' => 'bar']
```

#### Is &amp; Not

[](#is--not)

`Is` and `Not` are an inverse subset of `Filter`. The `Is` statement is simply an alias of `Filter` to minimize conceptual overhead. The `Not` filter is the inverse version of `Is` and reverses whatever filtering is applied.

```
$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->is('equals',['bar']);

var_dump($filter()); // ['foo' => 'bar']
```

Conversely...

```
$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->not('equals',['bar']);

var_dump($filter()); // ['boo' => 'baz']
```

#### Using callbacks

[](#using-callbacks)

Custom callbacks may easily be applied to every member of an array or object. Filter callbacks that return true or any values other than false or null will be kept in the subject array/object.

```
$filter = filtratr\with([
    'foo' => 'bar',
    'boo' => 'baz'
])->is(function($val) {
    if($val === 'bar') {
        return true;
    }
});

var_dump($filter()); // ['foo' => 'bar']
```

#### Using named callbacks

[](#using-named-callbacks)

Specifying a key name before the callback will then only apply the callback to items that match that key and exclude processing anything else. Non-matching keys will be retained by default.

```
$filter = filtratr\with([
    'foo' => 'bar',
    'bar' => 'baz'
])->is('foo', function($val) {
    if($val === 'bar') {
        return true;
    }
});

var_dump($filter()); // ['foo' => 'bar', 'bar' => 'baz']
```

#### Predicates &amp; Filters

[](#predicates--filters)

- equals(comparison)
- identical(comparison)
- greaterthan(comparison)
- greaterthanorequals(comparison)
- lessthan(comparison)
- lessthanorequals(comparison)
- validate(filter, options)
- serial

### Map

[](#map)

Map performs a transformation on selected keys/properties using a callback function.

#### Using callbacks

[](#using-callbacks-1)

Much like filter, map may receive a callback, optional key pattern, and callback arguments array. Unlike filter, map is not inclusive and as such map can only effectively result with a transformed value or the original value.

```
$filter = filtratr\with([
    'foo' => ' bar ',
    'fiz' => ' buz '
])->map(function($val) {
    return trim($val);
});

var_dump($filter()); // ['foo' => 'bar', 'fiz' => 'buz']
```

Callbacks of any type (string, Closures, arrays) may be used. The following example is functionally identical to the previous

```
\filtratr\with([
    'foo' => ' bar ',
    'fiz' => ' buz '
])->map('trim');

var_dump($filter()); // ['foo' => 'bar', 'fiz' => 'buz']
```

#### Using named callbacks

[](#using-named-callbacks-1)

```
$filter = filtratr\with([
    'foo' => ' bar ',
    'bar' => ' baz '
])->map('foo', 'trim');

var_dump($filter()); // ['foo' => 'bar', 'bar' => ' baz ']
```

#### Concatenated Expressions

[](#concatenated-expressions)

Mapping may be chained easily using the `|` pipe operation. Method chaining is alternatively an option as well.

```
$filter = filtratr\with([
    'foo' => ' bar',
    'fiz' => 'buz '
])
->map('trim | strtoupper');

var_dump($filter()); // ['foo' => 'BAR', 'fiz' => 'BUZ']
```

Same method using chaining...

```
$filter = filtratr\with([
    'foo' => ' bar',
    'fiz' => 'buz '
])
->map('trim')
->map('strtoupper');

var_dump($filter()); // ['foo' => 'BAR', 'fiz' => 'BUZ']
```

#### Predicates &amp; Filters

[](#predicates--filters-1)

- contains
- nuller
- empty\_nuller
- serializearray(array)
- unserializestring(string)

### Reduce

[](#reduce)

Like `array_reduce`, the reduce statement will apply a callback to many items and produce a single result.

```
$filter = filtratr\with([
    1, 2, 3, 4
])->reduce(function($a,$b) {
    return $a * $b;
});

var_dump($filter()[0]); // 24
```

### Object support

[](#object-support)

filtratr will technically work on objects however filtratr currently only tests on public properties. Objects are passed by reference and the query will assume the object is mutable.

```
class User {
    public $name;

    function __construct($name) {
        $this->name = $name;
    }
}

$user = new User(' john smith ');

$filter = filtratr\with($user)->map('name', 'trim | strtoupper')

var_dump($filter()->name); // "JOHN SMITH"
```

### Extending fluid interface

[](#extending-fluid-interface)

The extension class...

```
namespace MyQueryExtension;

class MyExtension extends filtratr\Query\AbstractStatement {
    /* do stuff here */
}
```

Attaching per-filter extensions...

```
$filter = new filtratr\with([
    'foo' => 'bar'
])
->extend('MyQueryExtension')
->myextension();

var_dump($filter());
```

Attaching globally...

```
filtratr\extend('MyQueryExtension');

$filter = new filtratr\with([
    'foo' => 'bar'
])
->myextension();

var_dump($filter());
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

4123d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e60e96f18d8a9dc2aff1363eedbaf210acc96666e7497d2a83d5a416ef397295?d=identicon)[jgswift](/maintainers/jgswift)

---

Top Contributors

[![jgswift](https://avatars.githubusercontent.com/u/661738?v=4)](https://github.com/jgswift "jgswift (7 commits)")

---

Tags

phparrayfilterfunctional-programming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jgswift-filtratr/health.svg)

```
[![Health](https://phpackages.com/badges/jgswift-filtratr/health.svg)](https://phpackages.com/packages/jgswift-filtratr)
```

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)[mpetrovich/dash

A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.

10428.9k1](/packages/mpetrovich-dash)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
