jedibc / decorator-stack
A simple tool for stacking decorators
Installs: 3 482
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.4
- psr/log: ~1.0
Requires (Dev)
- m6web/coke: ~1.0
- m6web/symfony2-coding-standard: ~1.1
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-12-21 18:09:22 UTC
README
A simple tool for stacking decorators.
Installation
The recommended way to install the library is through Composer. Require the jedibc/decorator-stack
package into your composer.json
file:
{ "require": { "jedibc/decorator-stack": "@stable" } }
Usage
Currently, if you want to decorate an object, you'll have to do something like this :
$decoratedObject = new Foo\Bar\Decorator1( new Foo\Bar\Decorator2( new Foo\Bar\Decorator3( new ObjectToDecorate() ), [$someConstuctorArgument]) );
The more decorators you have, the more ugly your code become.
With DecoratorStack, you can simplify it :
$stack = (new DecoratorStack\Builder('Foo\Bar\DummyInterface')) ->push('Foo\Bar\Decorator1') ->push('Foo\Bar\Decorator2', [$someConstuctorArgument]) ->push('Foo\Bar\Decorator3'); $decoratedObject = $stack->resolve(new ObjectToDecorate())
Each decorator and the object to decorate must implement the Foo\Bar\DummyInterface
(or it can be extending an abstract class).
Inspiration
License
DecoratorStack is released under the MIT License. See the bundled LICENSE file for details.