Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

duckoder/pdecorate

Repository files navigation

pdecorate

CircleCI

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>

About

Emulates Python decorators in PHP

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.md

Stars

Watchers

Forks

Packages

No packages published

Languages