Illuminate Collections
A fluent, chainable wrapper around PHP arrays with 170+ methods for mapping, filtering, reducing, and lazily evaluating data.
Repository Health
Technical Analysis
Illuminate Collections is the array-handling component extracted from Laravel’s illuminate/support, distributed here as a read-only subtree split so it can be installed on its own outside a full Laravel application. It wraps PHP arrays in a Collection object that exposes a fluent, chainable API — map, filter, reduce, groupBy, pluck, sortBy, and well over a hundred other methods — so that transforming and querying in-memory data reads like a pipeline instead of a sequence of nested array_* calls.
Alongside Collection, the package ships LazyCollection, which implements the same Enumerable contract over PHP generators so large or infinite sequences can be processed without loading everything into memory, and Arr, a static helper class for dot-notation array access (Arr::get, Arr::set, data_get) independent of the collection object itself. Both collection classes share behavior through the EnumeratesValues trait and support runtime extension via Macroable, letting applications add custom methods without subclassing.
What You Get
- A
Collectionclass with 170+ chainable methods covering mapping, filtering, sorting, grouping, aggregation, and set operations LazyCollectionfor processing large or infinite datasets via generators without holding the full set in memoryArrstatic helper class for dot-notation access, merging, and manipulation of plain PHP arrays- Global helper functions (
collect(),data_get(),data_set(),head(),last(),value()) autoloaded for use anywhere in a codebase HigherOrderCollectionProxyfor terse one-liners like$collection->each->save()instead of an explicit closureMacroablesupport so applications and packages can register additional collection methods at runtime
Common Use Cases
- Transforming API response payloads or database result sets into shaped view data
- Streaming and processing large CSV/log files lazily without exhausting memory
- Aggregating and grouping collections of domain objects (totals, averages, groupBy category)
- Replacing verbose nested
array_map/array_filter/array_reducechains with readable pipelines - Building reusable data-access helpers via dot-notation
Arr/data_geton deeply nested config or JSON structures
Under The Hood
Architecture
The package centers on the Enumerable interface, implemented by both Collection (eager, array-backed) and LazyCollection (deferred, generator-backed), with shared iteration and aggregation logic factored into the EnumeratesValues trait rather than a base class — avoiding an inheritance hierarchy while keeping the two implementations behaviorally consistent. Collection additionally implements ArrayAccess for bracket-style access and composes Macroable and TransformsToResourceCollection as traits, so runtime extensibility and resource-conversion behavior are opt-in capabilities rather than baked into the class itself. Arr and the global helpers in helpers.php/functions.php are deliberately kept outside the object model as static/procedural utilities, so callers who only need dot-notation array access aren’t forced to instantiate a Collection. The result is a flat, single-namespace (Illuminate\Support) library with no framework coupling beyond thin sibling packages.
Tech Stack
Requires PHP ^8.3 and depends only on other decoupled Illuminate components — illuminate/conditionable, illuminate/contracts, and illuminate/macroable — plus Symfony polyfills for PHP 8.4/8.5 forward compatibility, keeping the dependency footprint minimal for a package meant to be usable outside Laravel. There’s no build step; PSR-4 autoloading handles the class files and Composer’s files autoload mechanism loads functions.php and helpers.php so collect(), data_get(), and friends are globally available once the package is required.
Code Quality
This repository is a read-only subtree split of laravel/framework (its .github workflow exists only to redirect pull requests back upstream), so no test suite is visible here — Collection’s tests live in the monorepo, not this mirror. What is visible is unusually thorough: every public method carries PHPDoc with PHPStan/Psalm-style generic annotations (@template, @template-covariant, @implements), giving IDEs and static analyzers precise type inference through chained calls despite PHP’s own type system having no native generics.
API Design
The defining trait is fluency: collect($array)->filter(...)->map(...)->values() reads as a pipeline, and HigherOrderCollectionProxy shortens common closures further ($collection->each->save(), $collection->sum->amount). LazyCollection exposes the identical method surface as Collection, so switching from eager to lazy evaluation for a large dataset requires no API relearning — only a different constructor entry point. Boilerplate to get started is minimal: a bare array becomes a full-featured collection via a single collect() call, with no configuration or setup required.
Used by 2 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Mautic
Automation · Marketing · Ecommerce
The world's largest open source marketing automation platform — own your data, run multi-channel campaigns, and escape vendor lock-in forever.