nalabdou/algebra-symfony 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nalabdou/algebra-symfony

Composer 安装命令:

composer require nalabdou/algebra-symfony

包简介

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

README 文档

README

PHP Symfony License: MIT

Symfony 7 bundle for algebra-php — the pure PHP relational algebra engine.

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

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 separate nalabdou/algebra-twig [Comming soon] package.

Quick start

Algebra::from() — 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

// 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

// 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

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();

Configuration

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

Injectable services

Service ID Class Public
algebra.factory CollectionFactory
algebra.evaluator ExpressionEvaluator
algebra.aggregates AggregateRegistry
algebra.adapter_registry AdapterRegistry

Requirements

Version
PHP ≥ 8.2
nalabdou/algebra-php ^1.0
symfony/framework-bundle ^7.0

Optional: doctrine/orm ^3.0, doctrine/collections ^2.0

nalabdou/algebra-symfony 适用场景与选型建议

nalabdou/algebra-symfony 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「bundle」 「doctrine」 「pipeline」 「relational」 「algebra」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nalabdou/algebra-symfony 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nalabdou/algebra-symfony 我们能提供哪些服务?
定制开发 / 二次开发

基于 nalabdou/algebra-symfony 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-15