ryanve / traits
PHP traits for making extensible classes.
0.9.0
2014-01-14 16:24 UTC
Requires
- php: >=5.4
README
opensource PHP traits
Data
includes data/removeData methods.Emitter
is an event emitter based on EventEmitter.Mixin
is for making extensible classes.Aware
includes instantiation and context helpers.
Usage
Import into a class
class Example { use \traits\Mixin; }
Static mixins
static key/value mixin
Example::mixin('foo', function() { return 'bar'; });
static array mixin
Example::mixin([ 'foo' => function() { return 'bar'; } ]);
static method call
Example::foo(); # 'bar'
Instance mixins
Specify instance methods by passing true
static key/value mixin
Example::mixin('foo', function() { return 'bar'; }, true);
instance array mixin
Example::mixin([ 'foo' => function() { return 'bar'; } ], true);
instance method call
$example = new Example; Example->foo(); # 'bar'