PHPackages                             colybri/criteria - 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. [Search &amp; Filtering](/categories/search)
4. /
5. colybri/criteria

ActiveLibrary[Search &amp; Filtering](/categories/search)

colybri/criteria
================

Helper classes for implement filter/criteria pattern

v1.0.2(4y ago)060MITPHPPHP ^8.1

Since Feb 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/colybri/criteria)[ Packagist](https://packagist.org/packages/colybri/criteria)[ RSS](/packages/colybri-criteria/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

Criteria
========

[](#criteria)

This package allows build customized criteria and any kind of filters and also include an adapter for use with Doctrine Database Abstraction Layer.

Domain Driven Design series
---------------------------

[](#domain-driven-design-series)

This package is the first of a series of high level building blocks to build your applications with Domain Driven Design approach.

- [Criteria](#)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Create a criteria](#create-a-criteria)
    - [Specify order](#specify-order)
    - [Limit results](#limit-results)
    - [Nested filters](#nested-filters)
- [Adapter](#adapter)
    - [Dbal adapter](#dbal-adapter)
    - [Map database fields](#map-database-fields)

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

[](#installation)

Via Composer

```
$ composer require colybri/criteria
```

Usage
-----

[](#usage)

### Create a criteria

[](#create-a-criteria)

```
new Criteria(
    Filters::from([
        Filter::from(
            FilterField::from(CountryName::class),
            FilterOperator::Contains,
            FilterValue::from('Samoa')
         ),
        Filter::from(
            FilterField::from(CountryAlpha2Code::class),
            FilterOperator::Contains,
            FilterValue::from('WS')
        )
        ...
    ]),
    Order::from(OrderBy::from(CountryName::class), OrderType::Desc),
    0,
    100
);
```

A filter is composed by three objects. First is field key to match with your key/value map of field's names of your columns on database. Second parameter is the operator you want to use on your condition. The last one is the value you want to match.

### Specify order

[](#specify-order)

First parameter is the key of the field for order result. Secondly, order type.

```
Order::from(OrderBy::from(CountryName::class), OrderType::Desc),
```

### Limit results

[](#limit-results)

If you don't want to limit your results simply set `null` to the two last parameters of `Criteria`. Otherwise set offset and limit.

### Nested filters

[](#nested-filters)

In order use logic operator `OR` or nested conditions.

```
new Criteria(
    Filters::from(
        Conjunction::fromfilters(
            Disjunction::fromfilters(
                Filter::from(
                    FilterField::from(CountryAlpha2Code::class),
                    FilterOperator::Equal,
                    FilterValue::from('SW')
                 ),
                Filter::from(
                    FilterField::from(CountryAlpha2Code::class),
                    FilterOperator::Equal,
                    FilterValue::from('WS')
                )
                ...
            ),
            Filter::from(
                 FilterField::from(CountryName::class),
                 FilterOperator::Contains,
                 FilterValue::from('Samoa')
            ),
            ...
        )
    ),
    Order::none(),
    null,
    null
);
```

Adapter
-------

[](#adapter)

### Dbal adapter

[](#dbal-adapter)

In your repository:

```
        $query = $this->dbalConnection->createQueryBuilder()
            ->select('*')->from('countries');

        (new CriteriaDbalAdapter($query, new CountryMap()))->build($criteria);

        $countries = $query->executeQuery()->fetchAllAssociative();
```

### Map database fields

[](#map-database-fields)

In the above example `CountryMap` is a simple class that must implement `EntityMap` interface. As show bellow. The attribute `FIELDS` is a key/value array where the key is the semantic name that you use on your domain and the value is the column name that match on database.

```
final class CountryMap implements EntityMap
{
    private const FIELDS = [
        CountryName::class => 'en_short_name',
        CountryAlpha2Code::class => 'alpha_2_code'
    ];

    private const TABLE = 'countries';

    public function map(string $attribute): string
    {
        return self::FIELDS[$attribute];
    }

    public static function table(): string
    {
        return self::TABLE;
    }
}
```

Credits
-------

[](#credits)

- [Mario J. López](https://github.com/colybri)

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

1539d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/colybri-criteria/health.svg)

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[backpack/crud

Quickly build admin interfaces using Laravel, Bootstrap and JavaScript.

3.4k3.7M223](/packages/backpack-crud)[loupe/loupe

A full text search engine with tokenization, stemming, typo tolerance, filters and geo support based on only PHP and SQLite

508254.9k27](/packages/loupe-loupe)[shopware/elasticsearch

Elasticsearch for Shopware

153.9M19](/packages/shopware-elasticsearch)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[shopware/storefront

Storefront for Shopware

684.6M233](/packages/shopware-storefront)

PHPackages © 2026

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