PHPackages                             brezgalov/php-typed-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. brezgalov/php-typed-collection

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

brezgalov/php-typed-collection
==============================

base class for making typed collections via PHP iterator

128PHP

Since Mar 31Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Brezgalov/php-typed-collection)[ Packagist](https://packagist.org/packages/brezgalov/php-typed-collection)[ RSS](/packages/brezgalov-php-typed-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#installation)

```
composer require brezgalov/php-typed-collection dev-master

```

Description
-----------

[](#description)

Abstraction designed to make typed collections based on **Iterator** interface

If you need more functions - feel fre to add them to your custom implementation. You can implement ArrayAccess when it required

Usage
-----

[](#usage)

```
class MyClassCollection extends AbstractTypedIterator
{
    /**
     * override to set collection element type
     */
    public function current(): MyClass
    {
        return parent::current();
    }

    /**
     * Make shure items are same type
     */
    protected function validateItem($item): bool
    {
        return $item instanceof MyClass;
    }
}

// now go use

$collection = new MyClassCollection([
    new MyClass(),
    new MyClass(),
    new MyClass(),
]);

foreach($collection as $class) {
    // $class instance of MyClass - put your handle logic here
}

```

Deep cloning
------------

[](#deep-cloning)

Objects stored inside collection are references.

If you want to clone collection safely - consider using **ContainerDeepCloneTrait** or **AbstractTypedCloneSafeIterator** as it shown below:

**ContainerDeepCloneTrait**:

```
class MyClassCollection extends AbstractTypedIterator
{
    use ContainerDeepCloneTrait;

    public function current(): MyClass
    {
        return parent::current();
    }

    protected function validateItem($item): bool
    {
        return $item instanceof MyClass;
    }
}

$clone = clone $myClassCollection; // it's deep cloned now

```

**AbstractTypedCloneSafeIterator**:

```
class MyClassCollection extends AbstractTypedCloneSafeIterator
{
    ...
}

function testClone() {
    $myClass = new MyClass();
    $array = [$myClass];

    return new MyClassCollection($array); // $myClass is cloned
}

```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba5437e2f11c8cf8548822ad3c8e80eb9f9e84d266daf340e72681195aa7810d?d=identicon)[Brezgalov](/maintainers/Brezgalov)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/brezgalov-php-typed-collection/health.svg)

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

PHPackages © 2026

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