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

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

mehradsadeghi/laravel-decorator
===============================

Decorate and extend functionalities of methods without causing any break to the existing codebase.

v1.1.0(5y ago)151MITPHPPHP ^7.1

Since Jul 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/mehradsadeghi/laravel-decorator)[ Packagist](https://packagist.org/packages/mehradsadeghi/laravel-decorator)[ Docs](https://github.com/mehradsadeghi/laravel-decorator)[ RSS](/packages/mehradsadeghi-laravel-decorator/feed)WikiDiscussions master Synced 2d ago

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

Laravel Decorator
=================

[](#laravel-decorator)

#### Decorate and extend functionalities of methods without causing any break to the existing codebase.

[](#decorate-and-extend-functionalities-of-methods-without-causing-any-break-to-the-existing-codebase)

### Installation

[](#installation)

`$ composer require mehradsadeghi/laravel-decorator`

### Usage

[](#usage)

Assuming you have a class named `Person` with a method named `getFullName` which its inputs and output should get decorated:

```
class Person {

    public function makeFullName($firstName, $lastName)
    {
        return "$firstName $lastName";
    }
}

$person = new Person();
$person->makeFullName('mehrad', 'sadeghi'); // mehrad sadeghi
```

When using `decorator` without setting any decoration, The default behavior of `makeFullName` method will remain the same:

```
decorate([Person::class, 'makeFullName'], ['mehrad', 'sadeghi']); // mehrad sadeghi
```

In order to decorate `makeFullName` method:

```
$decorator = function ($callable) {
    return function (...$params) use ($callable) {

        // decorating the inputs
        foreach($params as $key => $param) {
            $params[$key] = trim($param);
        }

        // real call to makeFullName method
        $output = app()->call($callable, $params);

        // decorating the output
        $output = strtoupper($output);

        return $output;
    };
};

decorator([Person::class, 'makeFullName'])->set($decorator);
```

**Note** that the `decorator` should be a valid PHP callable. So it can be a `Closure` or an array callable, Which can be defined as follows:

```
class PersonDecorator {

    public function decorateFullName($callable)
    {
        return function (...$params) use ($callable) {

            // decorating the inputs
            foreach($params as $key => $param) {
                $params[$key] = trim($param);
            }

            // real call to makeFullName method
            $output = app()->call($callable, $params);

            // decorating the output
            $output = strtoupper($output);

            return $output;
        };
    }
}

decorator([Person::class, 'makeFullName'])->set([PersonDecorator::class, 'decorateFullName']);
```

Now we've assigned our decorator to the `makeFullName` method. Calling `makeFullName` with `decorate` helper function will apply its decoration:

```
decorate([Person::class, 'makeFullName'], ['  mehrad ', '     sadeghi ']); // MEHRAD SADEGHI
```

#### Multiple Decorators

[](#multiple-decorators)

You can easily set multiple decorators on a method:

```
decorator([Person::class, 'makeFullName'])
        ->set(function($callable) {
            // decoration
        })
        ->set(function($callable) {
            // decoration
        });
```

or

```
decorator([Person::class, 'makeFullName'])
    ->set([PersonDecorator::class, 'secondDecorator'])
    ->set([PersonDecorator::class, 'firstDecorator']);
```

#### Forgetting (Removing) Decorator(s)

[](#forgetting-removing-decorators)

You can easily remove one or all decorators assigned to a callable. From example above, Assume we have two decorators:

```
class PersonDecorator {

    public function decorateInput($callable)
    {
        return function (...$params) use ($callable) {

            // decorating the inputs
            foreach($params as $key => $param) {
                $params[$key] = trim($param);
            }

            // real call to makeFullName method
            $output = app()->call($callable, $params);

            return $output;
        };
    }

    public function decorateOutput($callable)
    {
        return function (...$params) use ($callable) {

            // real call to makeFullName method
            $output = app()->call($callable, $params);

            // decorating the output
            $output = strtoupper($output);

            return $output;
        };
    }
}

decorator([Person::class, 'makeFullName'])
    ->set([PersonDecorator::class, 'decorateInput'])
    ->set([PersonDecorator::class, 'decorateOutput']);
```

The output of calling `decorate` would be:

```
decorate([Person::class, 'makeFullName'], ['  mehrad ', '     sadeghi ']); // MEHRAD SADEGHI
```

Then for removing `decorateOutput`:

```
decorator([Person::class, 'makeFullName'])
    ->forget([PersonDecorator::class, 'decorateOutput']);
```

And the output of calling `decorate` would be:

```
decorate([Person::class, 'makeFullName'], ['  mehrad ', '     sadeghi ']); // mehrad sadeghi
```

**Note** that for removing all decorations of a callable, just leave the `forget` parameter empty:

```
decorator([Person::class, 'makeFullName'])->forget();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

Total

5

Last Release

2120d ago

Major Versions

v0.5.0 → v1.0.02020-07-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/0061a96703c9d6f044d10d15451dd7118b1c83631a902aee9d1dacbd5a4d0902?d=identicon)[mehradsadeghi](/maintainers/mehradsadeghi)

---

Top Contributors

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

---

Tags

decoratordecorator patterndecorationlaravel-decorator

### Embed Badge

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

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

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)[imanghafoori/laravel-decorator

A package to easily decorate your function calls.

13913.0k](/packages/imanghafoori-laravel-decorator)

PHPackages © 2026

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