PHPackages                             biera/filter - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. biera/filter

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

biera/filter
============

v1.1.0(3y ago)14.2kMITPHP

Since Oct 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/biera/filter)[ Packagist](https://packagist.org/packages/biera/filter)[ RSS](/packages/biera-filter/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

biera/filter
============

[](#bierafilter)

This package features a tiny lib which aims to ease every web-app project's problem: filtering. It's storage agnostic (check available [bindings](#bindings)) and comes with a micro-language which helps to build a "filter expression":

```
{
    "and": [
        {
            "lte": {"releaseDate": "2000-12-31"}
        },
        {
            "in": {"genre": ["biography", "drama"]}
        }
    ]
}

```

It should be pretty self-explanatory (if not, it reads *all drama and biography movies released in XX century*).

usage
-----

[](#usage)

Filter expression may be built directly using `Biera\Filter\Operator` which has constructor methods for all supported operators:

```
use Biera\Filter\Operator;

// all drama and biography movies released in XX century
$filterExpression = Operator::and(
    [
        Operator::lte('releaseDate', new DateTimeImmutable('2000-12-31')),
        Operator::in('genre', ['bigraphy', 'drama'])
    ]
);

assert($filterExpression instanceof Operator);
```

For more complex expressions, `Biera\Filter\FilterExpressionBuilder` with its fluent API may be a better option:

```
use Biera\Filter\Operator;
use Biera\Filter\FilterExpressionBuilder;

// all biography movies which are released before 2001-01-01 or last at least 120 minutes
$filterExpression = FilterExpressionBuilder::create()
    ->and()
        ->eq('genre', 'biography')
        ->or()
            ->lt('releaseDate', new DateTimeImmutable('2001-01-01'))
            ->gte('duration', 120)
        ->end()
    ->end()
    ->build();

assert($filterExpression instanceof Operator);
```

However, typically the filter expression is provided by client application as JSON encoded string, use `Biera\Filter\FilterExpressionFactory` is such cases:

```
use Biera\Filter\Operator;
use Biera\Filter\FilterExpressionFactory;

$filterExpression = FilterExpressionFactory::createFromJson($_GET['filters']);

assert($filterExpression instanceof Operator);
```

Alright, you have filter expression. What's next?

Usually, this lib is used together with one of existing [bindings](#bindings). For the purpose of demonstration let's use [doctrine ORM](https://github.com/biera/filter-doctrine-orm) binding to see it in action:

```
use Doctrine\ORM\EntityRepository;
use Biera\Filter\Operator as FilterExpression;
use Biera\Filter\Binding\Doctrine\ORM\WhereClauseFactory;

class MovieRepository extends EntityRepository
{
    public function findAllByFilters(FilterExpression $filters): array
    {
        $whereClause = WhereClauseFactory::createFromFilterExpression($filters);

        return $this->createQueryBuilder('movie')
            ->where($whereClause)
            ->getQuery()
            ->getResult();
    }
}
```

as you can see, it merely helps with the where clause. The job of joining, grouping and perhaps ordering still must be done by you.

installation
------------

[](#installation)

This lib is distributed as composer package and may be installed by typing:

```
composer require biera/filter

```

However, it's pretty useless without storage-specific binding, so consider to `require` a specific binding instead (which depends on `biera/filter` package).

bindings
--------

[](#bindings)

- [PDO](https://github.com/biera/filter-pdo)
- [doctrine ORM](https://github.com/biera/filter-doctrine-orm)
- mongo (work in progress)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~107 days

Total

3

Last Release

1446d ago

### Community

Maintainers

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

---

Top Contributors

[![biera](https://avatars.githubusercontent.com/u/3907377?v=4)](https://github.com/biera "biera (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/biera-filter/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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