PHPackages                             fattureincloud/api-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. [API Development](/categories/api)
4. /
5. fattureincloud/api-filter

ActiveLibrary[API Development](/categories/api)

fattureincloud/api-filter
=========================

A PHP parser for a sql-like filter

v2.0.0(1y ago)225.4k↓39.3%1[1 issues](https://github.com/fattureincloud/api-filter/issues)MITPHPPHP ^8.0

Since Nov 26Pushed 1y ago2 watchersCompare

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

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

FattureInCloud API Filter
=========================

[](#fattureincloud-api-filter)

This PHP library makes possible to parse a string parameter and use it to initialize a Filter that can be used on REST APIs; the input string is based on a simplified SQL-like WHERE clause, making it easy to understand and use.

The library returns a class-based representation of the filter, that can be used to generate the actual filter to apply to your API requests.

Disclaimer
----------

[](#disclaimer)

This library is currently focused on parsing and building the representation of the query, it does not validate the query itself. For example, it doesn't check if a field exists or if it is supported by your filters, and it doesn't enforce permissions checks on the query. You should take care of it on your own.

Even if this filter uses a grammar that should reduce the risk of [SQL Injection](https://owasp.org/www-community/attacks/SQL_Injection), you should adopt some strategy to validate the filters and avoid executing unsafe queries.

Install
-------

[](#install)

Via Composer

```
$ composer require fattureincloud/api-filter
```

Usage
-----

[](#usage)

To parse a filter string, you can use the *FattureInCloud\\ApiFilter\\FilterFactory* class:

```
use FattureInCloud\ApiFilter\FilterFactory

$str = "id = 5";
$factory = new FilterFactory();

$filter = $factory->initFilter($str);
```

The returned filter will be a composition of the classes contained in the *FattureInCloud\\ApiFilter\\Filter* package.

The string is based on triplets:

```
field op value

```

The **field** is a lowercase string, with dots and underscores.

The **op** is one of the following (unquoted):

- *Equal*: '='
- *Greater than*: '&gt;'
- *Greater than or equal to*: '&gt;='
- *Less than*: '&lt;'
- *Less than or equal to*: '&lt;='
- *Not equal*: '&lt;&gt;', '!='

The **value** can be one of:

- *String*: 'value'
- *Booleam*: true, false
- *Int*: 46
- *Double*: 12.34

You can *escape the single quote* in a string value by doubling it. The filter will take care of returning the expected string.

It is also possible to **match a String against a Pattern** using one of those operators:

- *Like*: 'like', 'LIKE'
- *Contains*: 'contains', 'CONTAINS'
- *Starts With*: 'starts with', 'STARTS WITH'
- *Ends With*: 'ends with', 'ENDS WITH'

Like and Contains can also be negated:

- *Not Like*: 'not like', 'NOT LIKE'
- *Not Contains*: 'not contains', 'NOT CONTAINS'

Additionally, it is possible to check if field has a value or not, using NULL:

- *Null field*: 'IS NULL', 'is null', '= null', '= NULL'
- *Not Null field*: 'IS NOT NULL', 'is not null', '&lt;&gt; null', '!= null', '&lt;&gt; NULL', '!= NULL'

It is possible to use the following operators:

- *Conjunction*: 'and', 'AND'
- *Disjunction*: 'or', 'OR'

Parenthesis can be used to compose complex expressions.

For example:

```
city = 'Bergamo' and (age < 30 or (dev = true and (name = 'Giorgio' and surname is not null) or employer starts with 'Fatture'))

```

Testing
-------

[](#testing)

```
$ composer test
```

Parser generation
=================

[](#parser-generation)

The parser was generated automatically using [ANTLR](https://www.antlr.org/) and the [PHP target](https://github.com/antlr/antlr4/blob/master/doc/php-target.md); it is placed in the *FattureInCloud\\ApiFilter\\Parser* repository. Usually you should not directly manage the parser: the **FilterFactory** class is a wrapper that manages it for you.

The grammar is placed under the */grammar* folder, if needed you can trigger the parser generation using docker and composer:

```
$ composer generate
```

If needed, you can generate a parser in another language changing the [ANTLR target](https://github.com/antlr/antlr4/blob/master/doc/targets.md) in the *entrypoint.sh* file.

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance24

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~126 days

Recently: every ~171 days

Total

9

Last Release

624d ago

Major Versions

v1.0.7 → v2.0.02024-09-02

PHP version history (3 changes)v1.0.0PHP ^7.2 || ^8.0

v1.0.4PHP ^7.4 || ^8.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bedf8b1b6f95ab71fbdfed85ffaa80abe343c313a945c8e57bc975c84c153e1?d=identicon)[m.valota.ts](/maintainers/m.valota.ts)

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

---

Top Contributors

[![valmoz](https://avatars.githubusercontent.com/u/7254293?v=4)](https://github.com/valmoz "valmoz (24 commits)")[![emajo](https://avatars.githubusercontent.com/u/48432054?v=4)](https://github.com/emajo "emajo (6 commits)")

---

Tags

antlrantlr-grammarantlr4antlr4-grammarapiapi-filterfilterparserphpquerysql-likewhereapifiltersql-likefattureincloudapi-filter

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)[joskolenberg/laravel-jory

Create a flexible API for your Laravel application using json based queries.

4513.5k](/packages/joskolenberg-laravel-jory)

PHPackages © 2026

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