PHPackages                             nalabdou/algebra-symfony - 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. [Database &amp; ORM](/categories/database)
4. /
5. nalabdou/algebra-symfony

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

nalabdou/algebra-symfony
========================

Symfony 7 bundle for algebra-php DI integration, Doctrine adapter.

1.1.0(3mo ago)04MITPHPPHP &gt;=8.2CI passing

Since Mar 15Pushed 3mo agoCompare

[ Source](https://github.com/nalabdou/algebra-symfony)[ Packagist](https://packagist.org/packages/nalabdou/algebra-symfony)[ RSS](/packages/nalabdou-algebra-symfony/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (10)Versions (4)Used By (0)

algebra-symfony
===============

[](#algebra-symfony)

[![PHP](https://camo.githubusercontent.com/187240af044d09d5b14a1d9d9ebdf3f7a993e4c7bc09bdb46b4ba661a891bf5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c7565)](https://php.net)[![Symfony](https://camo.githubusercontent.com/4ffba668c1acc64e3d3c942fe47359ffe900756c98fe9afc0e2b0dfdda18bac5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d372e782d626c61636b)](https://symfony.com)[![License: MIT](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

Symfony 7 bundle for [algebra-php](https://github.com/nalabdou/algebra-php) — the pure PHP relational algebra engine.

---

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

[](#installation)

```
composer require nalabdou/algebra-symfony
```

Symfony Flex registers the bundle automatically. Without Flex:

```
// config/bundles.php
return [
    Nalabdou\Algebra\Symfony\AlgebraBundle::class => ['all' => true],
];
```

---

What the bundle provides
------------------------

[](#what-the-bundle-provides)

FeatureDetailsDI services`algebra.factory`, `algebra.evaluator`, `algebra.aggregates`Custom aggregates`#[AsAggregate]` attribute — zero config, auto-registrationCustom adapters`#[AsAlgebraAdapter(priority: N)]` — auto-injected into CollectionFactoryDoctrine adaptersAuto-detected when `doctrine/orm` / `doctrine/collections` installed> **Twig filters** (`|algebra_where`, `|algebra_orderby`, ...) are provided by the separate `nalabdou/algebra-twig` \[*Comming soon*\] package.

---

Quick start
-----------

[](#quick-start)

### `Algebra::from()` — static, works as documented

[](#algebrafrom--static-works-as-documented)

```
use Nalabdou\Algebra\Algebra;

$result = Algebra::from($orders)
    ->where("item['status'] == 'paid'")
    ->groupBy('region')
    ->aggregate(['revenue' => 'sum(amount)', 'orders' => 'count(*)'])
    ->orderBy('revenue', 'desc')
    ->toArray();
```

Custom aggregates registered via `#[AsAggregate]` are available here after the first request (the `AlgebraBootstrapListener` re-registers them into Algebra's singleton registry after calling `Algebra::reset()`).

Custom aggregates
-----------------

[](#custom-aggregates)

```
// src/Aggregate/GeomeanAggregate.php
use Nalabdou\Algebra\Contract\AggregateInterface;
use Nalabdou\Algebra\Symfony\Attribute\AsAggregate;

#[AsAggregate]
final class GeomeanAggregate implements AggregateInterface
{
    public function name(): string { return 'geomean'; }

    public function compute(array $values): mixed
    {
        return empty($values) ? null : array_product($values) ** (1 / count($values));
    }
}
```

That's it — no `services.yaml`, no `Algebra::aggregates()->register()`. The bundle discovers it via `#[AsAggregate]` and auto-registers it.

```
// Now available everywhere
Algebra::from($products)
    ->groupBy('category')
    ->aggregate(['geoMeanPrice' => 'geomean(price)'])
    ->toArray();
```

---

Custom adapters
---------------

[](#custom-adapters)

```
// src/Adapter/CsvFileAdapter.php
use Nalabdou\Algebra\Contract\AdapterInterface;
use Nalabdou\Algebra\Symfony\Attribute\AsAlgebraAdapter;

#[AsAlgebraAdapter(priority: 50)]
final class CsvFileAdapter implements AdapterInterface
{
    public function supports(mixed $input): bool
    {
        return is_string($input) && str_ends_with($input, '.csv');
    }

    public function toArray(mixed $input): array { /* read CSV */ }
}
```

The adapter is auto-injected into the `algebra.adapter` service. Use :

```
$result = Algebra::from('/data/orders.csv')
    ->where("item['status'] == 'paid'")
    ->toArray();
```

---

Doctrine adapters
-----------------

[](#doctrine-adapters)

Automatically registered when the relevant packages are installed:

PackageInput type accepted`doctrine/collections``ArrayCollection`, `PersistentCollection``doctrine/orm``QueryBuilder````
composer require doctrine/orm
composer require doctrine/collections
```

```
// Doctrine QueryBuilder
$result = Algebra::from(
    $em->createQueryBuilder()->select('o')->from(Order::class, 'o')
)
->where("item['status'] == 'paid'")
->toArray();

// Doctrine Collection (e.g. from a OneToMany relation)
$result = Algebra::from($user->getOrders())
    ->orderBy('amount', 'desc')
    ->toArray();
```

---

Configuration
-------------

[](#configuration)

```
# config/packages/algebra.yaml
algebra:
    strict_mode: true   # throw on invalid expressions (default: true)
```

---

Injectable services
-------------------

[](#injectable-services)

Service IDClassPublic`algebra.factory``CollectionFactory`✓`algebra.evaluator``ExpressionEvaluator`✓`algebra.aggregates``AggregateRegistry`✓`algebra.adapter_registry``AdapterRegistry`✓---

Requirements
------------

[](#requirements)

VersionPHP≥ 8.2nalabdou/algebra-php^1.0symfony/framework-bundle^7.0**Optional:** `doctrine/orm ^3.0`, `doctrine/collections ^2.0`

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance81

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

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

Total

2

Last Release

102d ago

PHP version history (2 changes)1.0.0PHP ^8.2

1.1.0PHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![nalabdou](https://avatars.githubusercontent.com/u/46465503?v=4)](https://github.com/nalabdou "nalabdou (12 commits)")

---

Tags

algebraphpsymfony-bundlesymfonybundledoctrinerelationalpipelinealgebra

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nalabdou-algebra-symfony/health.svg)

```
[![Health](https://phpackages.com/badges/nalabdou-algebra-symfony/health.svg)](https://phpackages.com/packages/nalabdou-algebra-symfony)
```

PHPackages © 2026

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