Skip to content

atercattus/php-decorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-decorators

Build Status

The implementation of decorators in PHP

###Usage example

<?php
class Logger
{
    public static function log($func, $text='')
    {
        return function() use($func, $text) {
            printf("Log: %s\n", $text);
            return call_user_func_array($func, func_get_args());
        };
    }
}

function add($func, $v=0) {
    return function() use($func, $v) {
        return $v + call_user_func_array($func, func_get_args());
    };
}

# @Logger::log('calling b()')
# @add(41)
function b()
{
    return 1;
}

var_dump(b());

Returns:

Log: calling b()
int(42)

About

The implementation of decorators in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published