Download the PHP package mehradsadeghi/laravel-decorator without Composer
On this page you can find all versions of the php package mehradsadeghi/laravel-decorator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mehradsadeghi/laravel-decorator
More information about mehradsadeghi/laravel-decorator
Files in mehradsadeghi/laravel-decorator
Package laravel-decorator
Short Description Decorate and extend functionalities of methods without causing any break to the existing codebase.
License MIT
Homepage https://github.com/mehradsadeghi/laravel-decorator
Informations about the package laravel-decorator
Laravel Decorator
Decorate and extend functionalities of methods without causing any break to the existing codebase.
Installation
$ composer require mehradsadeghi/laravel-decorator
Usage
Assuming you have a class named Person
with a method named getFullName
which its inputs and output should get decorated:
When using decorator
without setting any decoration, The default behavior of makeFullName
method will remain the same:
In order to decorate makeFullName
method:
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:
Now we've assigned our decorator to the makeFullName
method. Calling makeFullName
with decorate
helper function will apply its decoration:
Multiple Decorators
You can easily set multiple decorators on a method:
or
Forgetting (Removing) Decorator(s)
You can easily remove one or all decorators assigned to a callable. From example above, Assume we have two decorators:
The output of calling decorate
would be:
Then for removing decorateOutput
:
And the output of calling decorate
would be:
Note that for removing all decorations of a callable, just leave the forget
parameter empty: