Illuminate Collections

A fluent, chainable wrapper around PHP arrays with 170+ methods for mapping, filtering, reducing, and lazily evaluating data.

Library
Composer
vv13.29.0
271stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity48
Maintenance0
Community76
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
64/100Good
Architecture80
Code Quality60
Innovation92
Learning Curve25

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 Collection class with 170+ chainable methods covering mapping, filtering, sorting, grouping, aggregation, and set operations
  • LazyCollection for processing large or infinite datasets via generators without holding the full set in memory
  • Arr static 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
  • HigherOrderCollectionProxy for terse one-liners like $collection->each->save() instead of an explicit closure
  • Macroable support 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_reduce chains with readable pipelines
  • Building reusable data-access helpers via dot-notation Arr/data_get on 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search