zhikiri / pdecorate
This package is abandoned and no longer maintained.
No replacement package was suggested.
Python like function decoration in PHP
v2.0.2
2018-01-22 17:18 UTC
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2022-12-10 20:32:48 UTC
README
Simulation of the Python decorators in PHP
Install with composer: composer require zhikiri/pdecorate
Description
Creation of the new decorator, second parameter must be callable.
Allow to use class methods, function names and Closure class instances (anonymous function)
Pdecorate::add('italic', function ($content) { return "<i>{$content}</i>"; });
Get instance of the decoration
First of all pass the decorators and the last parameter must be the callable function.
$decoration = new Decorator( 'italic', function () { return 'decoration text'; } );
Decoration execution:
- cast to string
(string)$decoration
- execute the Decorator instance
$decoration()
- run the Decorator call method
$decoration->call()
Result of the current decoration will be: <i>decoration text</i>