PHPackages                             darkdevlab/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. darkdevlab/collection

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

darkdevlab/collection
=====================

PHP realization of collections

1.0.0(6y ago)04MITPHPPHP &gt;=7.3CI failing

Since May 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/darkdevlab/collection)[ Packagist](https://packagist.org/packages/darkdevlab/collection)[ RSS](/packages/darkdevlab-collection/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

PHP COLLECTION
==============

[](#php-collection)

This component provides emulation of collection type for work with php

### INSTALLATION:

[](#installation)

```
composer require darkdevlab/collection
```

USAGE
=====

[](#usage)

#### Collection

[](#collection)

```
use DarkDevLab\Collection\Collection;

class User
{
    private $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function getName()
    {
        return $this->name;
    }
}

/**
 * @property User[] $container
 * @method User current()
 */
class UserCollection extends Collection
{
    public function addItem(User $user): self
    {
        return parent::add($user);
    }
}

$collection = new UserCollection();

$collection->addItem(new User('John'));
$collection->addItem(new User('John')); // Only one added. Duplication will be skipped
$collection->addItem(new User('Mark'));

foreach ($collection as $user) {
    echo sprintf('Username: %s', $user->getName()), PHP_EOL;
}
```

Output:

```
Username: John
Username: Mark

```

---

#### GeneratorCollection

[](#generatorcollection)

Lazy load collection

```
use DarkDevLab\Collection\GeneratorCollection;

class UserCollection extends GeneratorCollection
{

}

class UserRepository
{
    private $pdo;

    public function findAllByName(string $name): UserCollection
    {
        $stmt = $this->pdo->prepare('SELECT * FROM `user` WHERE name=:name');
        $generator = function () use ($stmt) {
            if ($stmt->execute()) {
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
                    if (!empty($row)) {
                        yield new User($row['name']);
                    }
                }
            } else {
                yield;
            }
        };

        return new UserCollection($generator());
    }
}

$userRepository =  new UserRepository(/* PDO */);
$userCollection = $userRepository->findAllByName('John');

foreach ($userCollection as $user) {
    echo sprintf('Username: %s', $user->getName()), PHP_EOL;
}
```

Output:

```
Username: John

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2205d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21e0957b4ef39743991b51833407f1823f4a4774d034699353e121a9d9f02090?d=identicon)[darkdevlab](/maintainers/darkdevlab)

---

Top Contributors

[![darkdevlab](https://avatars.githubusercontent.com/u/9559005?v=4)](https://github.com/darkdevlab "darkdevlab (4 commits)")

---

Tags

collectionphp collectionlazy load collection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

745663.8k13](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[lorisleiva/lody

Load files and classes as lazy collections in Laravel.

956.6M9](/packages/lorisleiva-lody)

PHPackages © 2026

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