PHPackages                             apicalypse/php-query-builder - 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. apicalypse/php-query-builder

ActiveLibrary[API Development](/categories/api)

apicalypse/php-query-builder
============================

PHP query builder for Apicalypse API \[IGDB\].

1.0.7(10mo ago)05MITPHPPHP &gt;=8.1

Since Jun 21Pushed 10mo agoCompare

[ Source](https://github.com/FernandoSilvera/apicalypse-php-query-builder)[ Packagist](https://packagist.org/packages/apicalypse/php-query-builder)[ Docs](https://github.com/FernandoSilvera/apicalypse-php-query-builder)[ RSS](/packages/apicalypse-php-query-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

Apicalypse PHP Query Builder
============================

[](#apicalypse-php-query-builder)

A lightweight, expressive query builder for Apicalypse-style APIs (like IGDB), written in pure PHP.

Build readable and validated API queries using a fluent interface. Supports field selection, filters, sorting, pagination, and search — with optional strict mode for better development error handling.

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

[](#installation)

Install via Composer:

```
composer require apicalypse/php-query-builder

```

[![Latest Version](https://camo.githubusercontent.com/e0a9d114556cbd7a5b07de64fd42f7642c34656ce92606e347af17b5aea2e4d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61706963616c797073652f7068702d71756572792d6275696c6465722e737667)](https://packagist.org/packages/apicalypse/php-query-builder)

Features
--------

[](#features)

- Add and exclude fields
- AND/OR conditional chaining
- Comparison operator support
- Pagination (limit + offset)
- Search support
- Sort by any field (ASC/DESC)
- Optional strict mode for debugging
- Input validation for safe query generation

Basic Usage
-----------

[](#basic-usage)

```
use Apicalypse\QueryBuilder;
use Apicalypse\Enum\ComparisonOperator;
use Apicalypse\Enum\SortDirection;

$query = new QueryBuilder();

$query->fields('name', 'release.date', 'game.platform.name')
    ->exclude('summary')
    ->where('rating > 80')
    ->andWhere(QueryBuilder::buildCondition('platforms', [6, 48], ComparisonOperator::CONTAINS_ANY))
    ->orWhere('(release.date < "2023-01-01" & release.date > "2022-01-01")')
    ->sort('release.date', SortDirection::DESC)
    ->limit(10)
    ->offset(0)
    ->search('Hollow Knight');

echo $query->build();

```

Output:

```
fields name,release.date,game.platform.name;
exclude summary;
where rating > 80 & platforms = (6, 48) | (release.date < "2023-01-01" & release.date > "2022-01-01");
sort release.date desc;
limit 10;
offset 0;
search "Hollow Knight";

```

### Strict Mode

[](#strict-mode)

Enable strict mode to throw exceptions during query building instead of returning a fallback string:

```
$query = new QueryBuilder(strict: true);

```

In non-strict mode, `__toString()` catches build exceptions and returns:

```
[ERROR] [INVALID __toString CALL]

```

### BuildCondition Examples

[](#buildcondition-examples)

```
QueryBuilder::buildCondition('name', 'Mario');
// name = "Mario"

QueryBuilder::buildCondition('rating', 90, ComparisonOperator::GT);
// rating > 90

QueryBuilder::buildCondition('tags', [1, 2], ComparisonOperator::CONTAINS_ANY);
// tags = (1, 2)

```

Public Methods
--------------

[](#public-methods)

- fields(string ...$fields)
- addFields(string ...$fields)
- exclude(string ...$fields)
- where(string $condition)
- andWhere(string $condition)
- orWhere(string $condition)
- sort(string $field, SortDirection $direction = SortDirection::ASC)
- limit(int $count)
- offset(int $offset)
- search(string $term)
- buildCondition(...) — static utility for field/value/operator
- clear()
- build() — builds the full query string
- \_\_toString() — safe string conversion with error fallback

Testing
-------

[](#testing)

Run PHPUnit tests:

```
composer test

```

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure:

- PSR-12 coding standards
- Tests cover new features or edge cases
- Public API changes are clearly documented

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)

Made with ❤️ for video game enthusiasts!

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance53

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Total

8

Last Release

325d ago

### Community

Maintainers

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

---

Top Contributors

[![FernandoSilvera](https://avatars.githubusercontent.com/u/100150904?v=4)](https://github.com/FernandoSilvera "FernandoSilvera (22 commits)")

---

Tags

apiapicalypseapicalypse-queryigdbphpphp-libraryphp8queryquery-builderphpapiquerybuilderquery builderigdbapicalypse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/apicalypse-php-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/apicalypse-php-query-builder/health.svg)](https://phpackages.com/packages/apicalypse-php-query-builder)
```

###  Alternatives

[gmostafa/php-graphql-client

GraphQL client and query builder.

3217.6M25](/packages/gmostafa-php-graphql-client)[gmostafa/php-graphql-oqm

GraphQL Object-to-Query Mapper (QOM) which generates objects from API schema

44898.8k2](/packages/gmostafa-php-graphql-oqm)

PHPackages © 2026

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