Opensource PHP traits
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Aware.php
Data.php
Emitter.php
Mixin.php
README.md
bootstrap.php
composer.json

README.md

traits (0.9)

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