PHPackages                             bolt/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bolt/collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bolt/collection
===============

Object Orientated implementations of various collections

v1.1.2(8y ago)12117.1k↓29.2%25MITPHPPHP ^5.5 || ^7.0

Since May 27Pushed 8y ago12 watchersCompare

[ Source](https://github.com/bolt/collection)[ Packagist](https://packagist.org/packages/bolt/collection)[ RSS](/packages/bolt-collection/feed)WikiDiscussions 1.1 Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (8)Used By (5)

Bolt Collection
===============

[](#bolt-collection)

[![travis](https://camo.githubusercontent.com/b72d15f051a8fa90c935b8c40f4307565ed66f56c993cbfb572c27f8bb5a076c/68747470733a2f2f6170692e7472617669732d63692e6f72672f626f6c742f636f6c6c656374696f6e2e737667)](https://travis-ci.org/bolt/collection)[![codecov](https://camo.githubusercontent.com/16d8100877ce7f911eac4efd63b657df3a2447fd81667a83d50381d02e07e607/68747470733a2f2f636f6465636f762e696f2f67682f626f6c742f636f6c6c656374696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/bolt/collection)

This library provides objects and functionality to help with groups of items and data sets.

Check out the [API documentation](https://docs.bolt.cm/api/bolt/collection/master/classes.html).

`Bag` and `MutableBag`
----------------------

[](#bag-and-mutablebag)

These are object-oriented implementations of arrays.

The goal of these classes:

- Provide functionality on par with built-in array methods
- Provide useful functionality lacking from built-in array methods
- Provide a fluent-like experience
- Make implementing code more readable

### Examples

[](#examples)

```
$arr = [
    'debug' => true,
    'color' => 'blue',
    'db' => [
        'driver' => 'sqlite',
    ],
];

$bag = Bag::from($arr)
    ->defaults([
        'debug' => false,
        'color' => 'green',
    ])
    ->replace([
        'color' => 'red',
    ])
;
$bag->get('debug'); // true
$bag->getPath('db/driver'); // "sqlite"
$bag->keys()->join(', '); // "debug, color, db"
$bag->isAssociative(); // true
```

```
$colors = MutableBag::of('red', 'blue', 'yellow')
    ->merge(['green', 'orange'])
;
$colors->isIndexed(); // true
$colors->indexOf('yellow'); // 2
$colors[2]; // "yellow"

$colors->prepend('purple');
$colors[] = 'pink';

$colors->first(); // "purple"
$colors->last(); // "pink"

$colors->shuffle()->first(); // one of the colors

$colors->chunk(2); // Bags represented as arrays:
// [ ['purple', 'red'], ['blue', 'yellow'], ['green, 'orange'], ['pink'] ]

$colors->removeFirst(); // "purple"
$colors->removeFirst(); // "red"
```

These examples only cover half of the functionality. See the [API documentation](https://docs.bolt.cm/api/bolt/collection/master/classes.html) for more.

All methods accepting a collection will accept other `Bags`, `arrays`, `stdClass`, and `Traversable` objects. This makes it very easy work with any collection-like object.

### Hasn't this been done already?

[](#hasnt-this-been-done-already)

Obviously others think PHP arrays suck as well and have attempted to resolve this.

Symfony's `ParameterBag` is a good basic *map* (associative arrays) container but is lacking when it comes to mutating the items around and working with lists.

Doctrine's `ArrayCollection` is also another, more robust, option. It works well for maps and lists, but still has limited functionality due to needing to interface with a database collection. It also has some annoyances, like `getKeys()` returns an `array` instead of another `ArrayCollection` instance.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 65.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~28 days

Total

6

Last Release

3093d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1835343?v=4)[Bob van de Vijver](/maintainers/bobvandevijver)[@bobvandevijver](https://github.com/bobvandevijver)

![](https://avatars.githubusercontent.com/u/3901745?v=4)[Tobias Feijten](/maintainers/tobias-93)[@tobias-93](https://github.com/tobias-93)

![](https://avatars.githubusercontent.com/u/1833361?v=4)[Bob den Otter](/maintainers/bobdenotter)[@bobdenotter](https://github.com/bobdenotter)

---

Top Contributors

[![CarsonF](https://avatars.githubusercontent.com/u/932566?v=4)](https://github.com/CarsonF "CarsonF (71 commits)")[![GwendolenLynch](https://avatars.githubusercontent.com/u/1427081?v=4)](https://github.com/GwendolenLynch "GwendolenLynch (38 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/bolt-collection/health.svg)

```
[![Health](https://phpackages.com/badges/bolt-collection/health.svg)](https://phpackages.com/packages/bolt-collection)
```

###  Alternatives

[phpdocumentor/reflection-docblock

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

9.4k722.2M1.2k](/packages/phpdocumentor-reflection-docblock)[icanhazstring/composer-unused

Show unused packages by scanning your code

1.7k7.0M188](/packages/icanhazstring-composer-unused)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12521.4M109](/packages/phpdocumentor-reflection)[sylius/promotion

Flexible promotion management for PHP applications.

28477.8k9](/packages/sylius-promotion)[sylius/taxonomy

Taxonomies - categorization of domain models in PHP projects.

14435.6k10](/packages/sylius-taxonomy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
