Loading repository data…
Loading repository data…
nalabdou / repository
Symfony 7 bundle for algebra-php DI integration, Doctrine adapter.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Symfony 7 bundle for algebra-php — the pure PHP relational algebra engine.
composer require nalabdou/algebra-symfony
Symfony Flex registers the bundle automatically. Without Flex:
// config/bundles.php
return [
Nalabdou\Algebra\Symfony\AlgebraBundle::class => ['all' => true],
];
| Feature | Details |
|---|---|
| DI services | algebra.factory, algebra.evaluator, algebra.aggregates |
| Custom aggregates | #[AsAggregate] attribute — zero config, auto-registration |
| Custom adapters | #[AsAlgebraAdapter(priority: N)] — auto-injected into CollectionFactory |
| Doctrine adapters | Auto-detected when doctrine/orm / doctrine/collections installed |
Twig filters (
|algebra_where,|algebra_orderby, ...) are provided by the separatenalabdou/algebra-twig[Comming soon] package.
Algebra::from() — static, works as documenteduse 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()).
// 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();
// 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();
Automatically registered when the relevant packages are installed:
| Package | Input 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();
# config/packages/algebra.yaml
algebra:
strict_mode: true # throw on invalid expressions (default: true)
| Service ID | Class | Public |
|---|---|---|
algebra.factory | CollectionFactory | ✓ |
algebra.evaluator | ExpressionEvaluator | ✓ |
algebra.aggregates | AggregateRegistry | ✓ |
algebra.adapter_registry | AdapterRegistry | ✓ |
| Version | |
|---|---|
| PHP | ≥ 8.2 |
| nalabdou/algebra-php | ^1.0 |
| symfony/framework-bundle | ^7.0 |
Optional: doctrine/orm ^3.0, doctrine/collections ^2.0