ryanve/traits

PHP traits for making extensible classes.

0.9.0 2014-01-14 16:24 UTC

This package is not auto-updated.

Last update: 2024-04-22 12:34:47 UTC


README

opensource PHP traits

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'

License

MIT