PHPackages                             bapcat/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. [File &amp; Storage](/categories/file-storage)
4. /
5. bapcat/collection

ActiveLibrary[File &amp; Storage](/categories/file-storage)

bapcat/collection
=================

Powerful but easy to use collections with support for lazy loading

0.5.1(9mo ago)0390[2 issues](https://github.com/BapCat/Collection/issues)3GPL-3.0-or-laterPHPPHP ^8.1

Since Nov 22Pushed 9mo ago4 watchersCompare

[ Source](https://github.com/BapCat/Collection)[ Packagist](https://packagist.org/packages/bapcat/collection)[ Docs](https://github.com/BapCat/Collection)[ RSS](/packages/bapcat-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (14)Used By (3)

[![Build Status](https://camo.githubusercontent.com/c2a59fbec766a261617be8cb38cd73ea96504a88b65d50a7b4061fb791b01d5b/68747470733a2f2f7472617669732d63692e6f72672f4261704361742f436f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BapCat/Collection)[![Coverage Status](https://camo.githubusercontent.com/008bb1f884bfebd6e8331e62845c8e5039766dfe25192ea61ac9a1f9a81c594e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4261704361742f436f6c6c656374696f6e2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/BapCat/Collection?branch=master)[![License](https://camo.githubusercontent.com/540b848dd728e5e67d6f743fc577836327ed1fb112c583d1805dc4ea06b27549/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f4261704361742f436f6c6c656374696f6e2e737667)](https://img.shields.io/packagist/l/BapCat/Collection.svg)

Collection
==========

[](#collection)

A modular, trait-based collection library that puts control of your data back in your hands.

Installation
------------

[](#installation)

### Composer

[](#composer)

[Composer](https://getcomposer.org/) is the recommended method of installation for Collection.

```
$ composer require bapcat/collection

```

### GitHub

[](#github)

This package may also be downloaded from [GitHub](https://github.com/BapCat/Collection/).

Features
--------

[](#features)

### Basic Collection Use

[](#basic-collection-use)

Collections make it easy to control access to your data in an object-oriented way. The standard implementation supports reading and writing, as well as standard `foreach` iteration.

```
$collection = new Collection(['k1' => 'v1']);

var_dump($collection->get('k1')); // 'v1'
var_dump($collection->size()); // 1

$collection->set('k2', 'v2');

$collection->add('v3');

// $collection == ['k1' => 'v1', 'k2' => 'v2', 'v3']

$collection->remove('k2');

// $collection == ['k1' => 'v1', 'v3']

foreach($collection as $k => $v) {
    //
}
```

### Custom Collections

[](#custom-collections)

Collections are built with traits, so it's easy to pick-and-choose the features you want. For example, you may want a collection that can't be modified from the outside:

```
class MyCollection implements ReadableCollectionInterface {
    use ReadableCollectionTrait;

    protected $collection = [];
}
```

If you would like to implement a full read/write collection, you may extend the basic `Collection` class:

```
class MyCollection extends Collection {
    //
}
```

Or, you may implement the interfaces and trait:

```
class MyCollection implements ReadableCollectionInterface, WritableCollectionInterface {
    use ReadableCollectionTrait, WritableCollectionTrait;
}
```

### Array Access

[](#array-access)

If you would like to use array access with your collection, use the `ArrayAccessCollection` class or the `ArrayAccessCollectionTrait` trait.

### Lazy Loading

[](#lazy-loading)

Writable collections have support for lazy-loading built in. Lazy loading can be very useful, for example, in database interactions.

```
$collection->lazy(1, function($key) {
    return User::find($key);
});
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance58

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 95.9% 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 ~394 days

Recently: every ~848 days

Total

10

Last Release

279d ago

PHP version history (3 changes)0.1PHP &gt;=5.6.0

0.4.0PHP ^7.4|^8.0

0.5PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/246ea082e8ed7f6e8ace29950179d4dfb1e3a58bac53aef49a3d2e43ab1e7f04?d=identicon)[LordMonoxide](/maintainers/LordMonoxide)

---

Top Contributors

[![LordMonoxide](https://avatars.githubusercontent.com/u/437657?v=4)](https://github.com/LordMonoxide "LordMonoxide (47 commits)")[![rascopeeko](https://avatars.githubusercontent.com/u/6076349?v=4)](https://github.com/rascopeeko "rascopeeko (2 commits)")

---

Tags

arraystoragecollectionlazyRead only

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[qiniu/php-sdk

Qiniu Resource (Cloud) Storage SDK for PHP

8483.0M240](/packages/qiniu-php-sdk)[sylius/resource-bundle

Resource component for Sylius.

23410.2M173](/packages/sylius-resource-bundle)[microsoft/azure-storage-blob

This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Blob APIs.

5516.0M60](/packages/microsoft-azure-storage-blob)

PHPackages © 2026

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