PHPackages                             pushoperations/decorators - 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. pushoperations/decorators

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

pushoperations/decorators
=========================

A library of decorators.

v1.0.0(10y ago)064[1 issues](https://github.com/pushoperations/Decorators/issues)MITPHPPHP &gt;=5.4.0

Since Jun 19Pushed 10y ago10 watchersCompare

[ Source](https://github.com/pushoperations/Decorators)[ Packagist](https://packagist.org/packages/pushoperations/decorators)[ Docs](https://github.com/pushoperations/Decorators)[ RSS](/packages/pushoperations-decorators/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Decorators
==========

[](#decorators)

[![Build Status](https://camo.githubusercontent.com/5c5ea5932f65d4618e78bd0af7df9913989fa6a7b0bce75d5b10091efb9b389d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f707573686f7065726174696f6e732f4465636f7261746f72732e737667)](https://travis-ci.org/pushoperations/Decorators)[![Coverage Status](https://camo.githubusercontent.com/88d3c215e428ea4131e3ea3ebcce476e202eca4fe978ac27d35f1f4d95faab4a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f707573686f7065726174696f6e732f4465636f7261746f72732e737667)](https://coveralls.io/r/pushoperations/Decorators)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/910d94d80b9c288bed422fc9307b2fecf95ba8a31a3d48b770808045d7ba12c5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f707573686f7065726174696f6e732f4465636f7261746f72732e737667)](https://scrutinizer-ci.com/g/pushoperations/Decorators/?branch=master)

[![Total Downloads](https://camo.githubusercontent.com/cec46be3cf84cee0c963549df6e238d1735540a6d5259d29d951a8bd25b63610/68747470733a2f2f706f7365722e707567782e6f72672f707573686f7065726174696f6e732f6465636f7261746f72732f646f776e6c6f6164732e737667)](https://packagist.org/packages/pushoperations/Decorators)[![Latest Stable Version](https://camo.githubusercontent.com/ece350501d3aa53ec1fe7a1d6cc7a56dff554a93e5ea6970add6c42e58f4f224/68747470733a2f2f706f7365722e707567782e6f72672f707573686f7065726174696f6e732f6465636f7261746f72732f762f737461626c652e737667)](https://packagist.org/packages/pushoperations/Decorators)[![Latest Unstable Version](https://camo.githubusercontent.com/5f670240316f0e035c3add1639cc8e39e732e52c7a17645262ea10074d813cb8/68747470733a2f2f706f7365722e707567782e6f72672f707573686f7065726174696f6e732f6465636f7261746f72732f762f756e737461626c652e737667)](https://packagist.org/packages/pushoperations/Decorators)[![License](https://camo.githubusercontent.com/8a1cbc51ab74f19d0710c39247883bf01b1651940041ce4a38843fd614d4982b/68747470733a2f2f706f7365722e707567782e6f72672f707573686f7065726174696f6e732f6465636f7261746f72732f6c6963656e73652e737667)](https://packagist.org/packages/pushoperations/Decorators)

A library to decorate arrays (especially Laravel's Input::) for manipulation and usage as a service to return data for object construction.

Note: *this library may contain other patterns in the future*.

Contents
--------

[](#contents)

- [Installation](#install)
- [Usage](#usage)
- [Examples](#examples)
- [API documentation](http://pushoperations.github.io/Decorators/docs)

Install
-------

[](#install)

The recommended way to install is through [Composer](http://getcomposer.org).

Update your project's composer.json file to include Decorators:

```
{
    "require": {
        "pushoperations/decorators": "1.*"
    }
}
```

Then update the project dependencies to include this library:

```
composer update pushoperations/decorators
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

Usage
-----

[](#usage)

Create your own decorator by:

- Extending from the `DataDecorator` abstract class
- Creating a constructor that accepts an array
- Optional: add methods that are specific to generating the array of data you need

One use case is to split input data into different arrays for different factories to use for the construction of new objects.

A handy effect is that you can perform sanitization within the decorator's methods before returning the data array.

Examples
--------

[](#examples)

```
use Push\Decorators\DataDecorator;
use Push\Decorators\DataDecoratorInterface;

class BasicDecorator extends DataDecorator implements DataDecoratorInterface
{
    public function __construct(array $input)
    {
        $this->data = $input;
    }
}

class ComplexDecorator extends DataDecorator implements DataDecoratorInterface
{
    public function __construct(array $input)
    {
        $this->data = $input;
    }

    public function complicate()
    {
        return array_map($this->data, function($value) {
            if (is_int($value)) {
                return $value * 2;
            }
        });
    }
}
```

Common usage would be to filter and pick apart the user input for create/update:

```
$input = [
    'name' => 'Push Operations',
    'desks' => 50,
    'employees' => [
        'John', 'Jane',
    ],
];

$basic = new BasicDecorator($input);

// Check if value for key exists
echo $basic->has('desks');                      // true
echo $basic->has('chairs');                     // false

// Provide a default value if it doesn't exist
echo $basic->get('name');                       // 'Push Operations'
echo $basic->get('chairs', 10);                 // 10

// Get some of the data
var_dump($basic->only('name', 'desks'));        // ['name' => 'Push Operations', 'desks' => 50]
var_dump($basic->only(['name', 'desks']));      // ['name' => 'Push Operations', 'desks' => 50]
var_dump($basic->except('name'));               // ['desks' => 50, 'employees' => ['John', 'Jane']]

// Get all of the data
var_dump($basic->all());                        // The $input array

// Add data
$add = [
    'interns' => [
        'Billy', 'Derrick'
    ],
];
$basic->merge($add);
var_dump($basic->get('interns'));               // ['Billy', 'Derrick']

// You can redecorate the results of the decorator (with itself or another decorator) to do more manipulation.

$complex = new ComplexDecorator($basic->all());
var_dump($complex->complicate());               // [..., 'desks' => 100, ...];
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

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

3986d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11966c19a7e0836010f22fff667040c7f7e371a4bfb6050c3fd5ad395171351d?d=identicon)[tonglil](/maintainers/tonglil)

---

Top Contributors

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

---

Tags

decoratorspatterndecorate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pushoperations-decorators/health.svg)

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

###  Alternatives

[league/pipeline

A plug and play pipeline implementation.

1.0k16.0M74](/packages/league-pipeline)[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81161.3k](/packages/getsolaris-laravel-make-service)[redeyeventures/geopattern

Generate beautiful SVG patterns.

11140.8k2](/packages/redeyeventures-geopattern)[functional-php/pattern-matching

Pattern matching for PHP with automatic destructuring.

8261.5k](/packages/functional-php-pattern-matching)[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5253.7k3](/packages/lezhnev74-pasvl)[ptrofimov/matchmaker

Ultra-fresh PHP matching functions

27167.7k](/packages/ptrofimov-matchmaker)

PHPackages © 2026

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