antevemus / alinq-collection
Enterprise LINQ-Style Collection Framework for PHP 8.4+ (Fluent API, Native Array Primitives, Query Builder, Set Operations, Dot-Notation Property Access)
Package info
github.com/antevemus-it/Antevemus.AlinqCollection
pkg:composer/antevemus/alinq-collection
Requires
- php: >=8.4
- antevemus/adeep-property-access: ^1.0.0
Requires (Dev)
- infection/infection: ^0.35.6
- phpunit/phpunit: ^11.0
Suggests
- ext-curl: Required by ALinqLazyCollection::fromHttpPages() (since 1.5.0) and fromHttpPagesByIndex() (since 2.4.0): lazy sources over a paginated HTTP API that prefetch the next pages with curl_multi
- ext-intl: Required by StringComparer::culture() (since 2.2.0): text compared by the collation rules of a language (ICU), ignoring case and/or accents, numeric ordering; without it culture() throws LogicException and ordinal()/ordinalIgnoreCase() keep working
- ext-mbstring: Required by StringComparer::ordinalIgnoreCase() (since 2.2.0): Unicode case folding; without it ordinalIgnoreCase() throws LogicException
- antevemus/alinq-parallel: ^1.0 — ALinqParallelCollection: selectParallel()/whereParallel()/selectManyParallel()/eachParallel() over a pool of PHP worker processes, for CPU-bound work per item (a Fiber alone is not parallelism); the work must be transportable to another process (a static method or a serializable invokable, never a closure)
- antevemus/alinq-revolt: ^1.0 — ALinqAsyncCollection: selectAsync()/whereAsync()/selectManyAsync()/eachAsync() over the Revolt event loop (Fibers, Amp futures) with an ordered, bounded window of items in flight, for I/O per item against asynchronous SDKs
- antevemus/aspecification: ^2.0.0 — Specification pattern with ALinqBridge and ALinqSpecificationVisitor: evaluate domain specifications over eager and lazy ALinq collections (docs/en/concepts/aspecification-synergy.md); since 2.0 both packages resolve property names through the same antevemus/adeep-property-access
Provides
None
Conflicts
None
Replaces
None
README
Enterprise LINQ-Style Collection Framework for PHP 8.4+
A fluent, expressive, and type-safe collection manipulation engine bringing the elegance of .NET Language Integrated Query (LINQ) to PHP. Powered by PHP 8.4 native array primitives (array_any,array_all,array_find,array_find_key), generator-based streaming pipelines (ALinqLazyCollection), advanced set theory, dynamic predicate query builders, dot-notation deep property resolution, and seamless bidirectional synergy withAntevemus.ASpecification.
🇺🇸 English • 🇧🇷 Português (Brasil)
The documentation lives in docs/en (English) and docs/pt-BR (Portuguese, Brazil), one page per topic, in the Docs Kit format (a docs-nav.json per language). The API Reference keeps the section numbers it had in this README (§9 is still ### 9., now on its own page), and every PHP block of the pages is checked by the test suite.
🚀 Quick Start
The same block opens Getting Started, and the test suite runs it with the answers written in its comments:
<?php declare(strict_types=1); use Antevemus\ALinq\ALinqCollection; $users = ALinqCollection::from([ ['id' => 1, 'name' => 'Alice', 'role' => 'admin', 'score' => 95, 'active' => true], ['id' => 2, 'name' => 'Bob', 'role' => 'editor', 'score' => 82, 'active' => true], ['id' => 3, 'name' => 'Charlie', 'role' => 'viewer', 'score' => 60, 'active' => false], ['id' => 4, 'name' => 'Diana', 'role' => 'admin', 'score' => 91, 'active' => true], ['id' => 5, 'name' => 'Evan', 'role' => 'editor', 'score' => 74, 'active' => true], ]); // 1. Fluent Query Pipeline $topActiveAdmins = $users ->where(fn($u) => $u['active'] && $u['role'] === 'admin') ->orderByDescending(fn($u) => $u['score']) ->select(fn($u) => sprintf('%s (%d pts)', $u['name'], $u['score'])) ->toArray(); // Result: ['Alice (95 pts)', 'Diana (91 pts)'] // 2. High-Performance Aggregations (Native PHP 8.4) $hasSuperUser = $users->any(fn($u) => $u['score'] > 90); // true (via array_any) $allActive = $users->all(fn($u) => $u['active']); // false (via array_all) $avgScore = $users->average(fn($u) => $u['score']); // 80.4 $bestUser = $users->maxBy(fn($u) => $u['score']); // ['id' => 1, 'name' => 'Alice'...] // 3. Grouping & Sub-Collection Aggregations $roleStats = $users ->groupBy(fn($u) => $u['role']) ->select(fn(ALinqCollection $group, string $role) => [ 'role' => $role, 'count' => $group->count(), 'avg_score' => $group->average(fn($u) => $u['score']), 'top_performer' => $group->maxBy(fn($u) => $u['score'])['name'], ]) ->toArray();
📦 Installation
Install via Composer: composer require antevemus/alinq-collection. Requirements: PHP 8.4 or later, and one dependency, installed with it: antevemus/adeep-property-access (from the same author, with no dependencies of its own), the property accessor shared with Antevemus.ASpecification. Upgrading from 1.x: see UPGRADE-2.0.md. Installing from the Git VCS repository: Getting Started.
📚 Documentation
One line per page, grouped as in the navigation; §N is the section of the API Reference that the page hosts, numbered as in the former README.
Getting started
- Installation and quick start · pt-BR: Composer, the Git VCS repository and the Quick Start.
Concepts
- Origins and philosophy · pt-BR: Why LINQ in PHP, and the six design principles of the library.
- Core features · pt-BR: Every operator of the library in one table, by domain.
- Architecture · pt-BR: The source tree: the main classes, the 11 interfaces and the 8 traits.
- Synergy with ASpecification · pt-BR: ASpecification rules evaluated over ALinq collections through
ALinqBridge.
API reference
- Factories (§1) · pt-BR:
from(),range(),repeat(),empty(),toArray()andtoObject(). - Filtering and slicing (§2) · pt-BR:
where(),take()/skip(),distinct(),first(),chunk()and the field filterswhereIn(),whereNotIn(),whereBetween(). - Joining and set theory (§3) · pt-BR: Inner and outer joins,
groupJoin(), the set operations andexceptByKeys()/intersectByKeys(), with an equality comparer since 2.4.0. - Aggregations and metrics (§4) · pt-BR:
any(),all(),sum(),average(),min()/max(),single()and the*OrDefault()aggregates. - Projections and transformations (§5) · pt-BR:
select(),selectMany(),column(),toDictionary(onDuplicate:)andtoLookup(). - Grouping and partitioning (§6) · pt-BR:
groupBy()into sub-collections, andALinqLookup, a materializedgroupBy(). - Sorting and ordering (§7) · pt-BR: Stable
orderBy()/thenBy(), natural and custom orderings, andStringComparer. - Dynamic query builder (§8) · pt-BR:
ALinqQueryBuilder: conditions inand/ormode, its operators andtoPredicate(). - Deep property access (§9) · pt-BR: Dot-notation paths, the resolution order and the
#[Specifiable]opt-in for non-public properties. - Streaming and big data (§10) · pt-BR:
ALinqLazyCollection: files, CSV, database cursors, paginated HTTP,remember()and the stages that accumulate data. - The contract (§11) · pt-BR: The rules both collections obey: keys, equality, group keys, empty collections, ordering, comparers, arguments and more.
Quality
Project
- Roadmap · pt-BR: Every release shipped and what comes next; the milestone view is in ROADMAP.md.
- License and authors · pt-BR: The MIT license, the author and the organization.
🧪 Quality
- Tests: 836 PHPUnit tests (
vendor/bin/phpunit) over the 8 traits, the streaming engine, the eager × lazy contract and the code blocks of the documentation, 100% passing on PHP 8.4. - Assertions: 4631 without
ext-intl(the 17 tests ofStringComparer::culture()skipped) and 4772 with it (1 skipped, the test of the missing extension); the CI runs both legs. - Coverage (pcov, 2.2.0, with
ext-intl): 289 of 299 methods and 1619 of 1637 lines ofsrc/; the 18 uncovered lines are defensive guards or depend on the environment. - Mutation testing: Infection on the lines changed since 2.1.0, MSI 97.59% (10 escaped mutants, all equivalent).
- Contract parity: every shared operation runs over the same inputs on the eager and the lazy collection, with zero divergences allowed (
tests/Contract/ParityTest.php; the rules: The contract). - The report, the coverage details and the mutation run: Tests.
🗺️ Roadmap & Ecosystem
Every release shipped and what comes next: Roadmap. The milestone view, with target releases: 👉 ROADMAP.md.
📄 License & Authors
This software is open-source, licensed under the MIT License.
- Author: Heliton Junior (CTO) —
contato@antevemus.com.br - Organization: Antevemus Soluções Inovadoras em TI Ltda.
- Copyright: Copyright (c) 2025–2026 Antevemus Soluções Inovadoras em TI Ltda.