PHPackages                             alcamo/decorator - 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. alcamo/decorator

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

alcamo/decorator
================

Base trait and class to create decorators

0.2.1(2w ago)0123↑50%2Apache-2.0PHPPHP 7.3 - 8.5

Since Oct 22Pushed 2w agoCompare

[ Source](https://github.com/rv1971/alcamo-decorator)[ Packagist](https://packagist.org/packages/alcamo/decorator)[ RSS](/packages/alcamo-decorator/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (8)Used By (2)

Usage example
=============

[](#usage-example)

```
use alcamo\decorator\Decorator;
use Ds\Set;

class SetWithSum extends Decorator implements \Countable, \IteratorAggregate
{
    public function __construct($values)
    {
        parent::__construct(new Set($values));
    }

    public function getSum(): int
    {
        $result = 0;

        foreach ($this as $value) {
            $result += $value;
        }

        return $result;
    }
}

$set = new SetWithSum([ 42, 42, 7]);

echo "Count: " . count($set) . "\n";

echo "Sum: " . $set->getSum() . "\n";

```

This will output:

```
Count: 2
Sum: 49

```

Overview
========

[](#overview)

The trait `DecoratorTrait` implements the [Decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) for an arbitrary object. The class `Decorator` uses this trait.

As in the example above, this can be used to create a class that adds functionality to a class when creating a derived class is not possible.

All functionality of the enclosed object is exposed by the decorator so that the decorator behaves just as the enclosed object, supporting, for instance, the Countable, Iterator or ArrayAccess interface.

The trait `MultiDecoratedTrait` offers a means to add multiple decorators to an object, indexed by their class nane. `MultiDecoratedArrayAccessTrait` is buil on top of this and allows to access the decorators via ArrayAccess methods.

See the doxygen documentation for details.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance97

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

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

Every ~40 days

Total

7

Last Release

15d ago

PHP version history (2 changes)0.1PHP 7.3 - 8.0

0.2.1PHP 7.3 - 8.5

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

decorator

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alcamo-decorator/health.svg)

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

PHPackages © 2026

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