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.
class Example {
use \traits\Mixin;
}
Example::mixin('foo', function() {
return 'bar';
});
Example::mixin([
'foo' => function() {
return 'bar';
}
]);
Example::foo(); # 'bar'
Specify instance methods by passing true
Example::mixin('foo', function() {
return 'bar';
}, true);
Example::mixin([
'foo' => function() {
return 'bar';
}
], true);
$example = new Example;
Example->foo(); # 'bar'