PHPackages                             sgh/decorate-anything - 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. sgh/decorate-anything

ActiveLibrary

sgh/decorate-anything
=====================

Abstract decorator class

2.0.0(11y ago)270BSDPHPPHP &gt;=5.3

Since Jun 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/schmengler/Decorate-Anything)[ Packagist](https://packagist.org/packages/sgh/decorate-anything)[ Docs](http://www.sgh-it.eu)[ RSS](/packages/sgh-decorate-anything/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Decorate Anything
=================

[](#decorate-anything)

- Synopsis
- Installation
- Requirements
- Usage

Synopsis
--------

[](#synopsis)

This package is a simplified implementation of the Decorator Design Pattern. Sub classes of the provided Decorator class may be used to decorate any objects without the need for abstract components and abstract decorators for each of them thanks to PHP's magic methods and loose typification.

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

[](#installation)

You can just download `Decorator.php` and include it anywhere, but I recommend using composer:

```
require: {
    "sgh/decorate-anything": "~2.0"
}

```

Requirements
------------

[](#requirements)

The package requires PHP 5.3 or later.

Usage
-----

[](#usage)

To create a decorator for a component, say ConcreteComponent, just extend the Decorator like this:

```
class ConcreteDecorator extends \SGH\DecorateAnything\Decorator
{
    const COMPONENT_CLASS = 'ConcreteComponent';
}

```

To extend functionality of a component method in the decorator, use the parent keyword like you would do in the original decorator pattern:

```
public function foo()
{
    parent::foo();
    some_special_functionality();
}

```

Now you can decorate your component like this:

```
$component = new ConcreteDecorator(new ConcreteComponent());

```

$component will have the same interface as ConcreteComponent, you also can access the public properties of the decorated component.

```
$component->foo();
$component->bar(1,2); // assuming a method ConcreteComponent::bar($x,$y)
var_dump($component->baz); // assuming a property ConcreteComponent::$baz
var_dump(isset($component->baz));
$component->baz = 1;
unset($component->baz);

```

If you really have to name the common interface of decorator and compontent explicitly do it this way:

```
interface IConcreteComponent
{
    public function foo();
    public function bar($x,$y);
}
class ConcreteComponent implements IConcreteComponent
{
    public $baz = 'baz';
    public function foo()
    {
        // implementation
    }
    public function bar($x,$y)
    {
        // implementation
    }
}
class ConcreteDecorator extends \SGH\DecorateAnything\Decorator implements IConcreteComponent
{
    const COMPONENT_CLASS = 'ConcreteComponent';
    public function foo()
    {
        parent::foo();
        // additional implementation
    }
    public function bar($x,$y)
    {
        return parent::bar($x,$y);
    }
}

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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 ~136 days

Total

2

Last Release

4207d ago

Major Versions

1.0.0 → 2.0.02014-11-06

PHP version history (2 changes)1.0.0PHP &gt;=5.2.6

2.0.0PHP &gt;=5.3

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/sgh-decorate-anything/health.svg)

```
[![Health](https://phpackages.com/badges/sgh-decorate-anything/health.svg)](https://phpackages.com/packages/sgh-decorate-anything)
```

PHPackages © 2026

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