https://github.com/ryanve/traits
Opensource PHP traits
https://github.com/ryanve/traits
php php-traits
Last synced: about 1 year ago
JSON representation
Opensource PHP traits
- Host: GitHub
- URL: https://github.com/ryanve/traits
- Owner: ryanve
- Created: 2013-04-03T20:52:33.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2014-01-14T16:25:43.000Z (over 12 years ago)
- Last Synced: 2025-04-02T18:56:27.950Z (about 1 year ago)
- Topics: php, php-traits
- Language: PHP
- Homepage:
- Size: 273 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [traits](../../) ([0.9](../../releases))
#### opensource [PHP traits](http://php.net/manual/en/language.oop5.traits.php)
- [`Data`](Data.php) includes data/removeData methods.
- [`Emitter`](Emitter.php) is an event emitter based on [EventEmitter](http://nodejs.org/api/events.html).
- [`Mixin`](Mixin.php) is for making extensible [classes](http://php.net/manual/en/language.oop5.php).
- [`Aware`](Aware.php) includes instantiation and context helpers.
## Usage
### Import into a class
```php
class Example {
use \traits\Mixin;
}
```
### Static mixins
#### static key/value mixin
```php
Example::mixin('foo', function() {
return 'bar';
});
```
#### static array mixin
```php
Example::mixin([
'foo' => function() {
return 'bar';
}
]);
```
#### static method call
```php
Example::foo(); # 'bar'
```
### Instance mixins
Specify instance methods by passing `true`
#### static key/value mixin
```php
Example::mixin('foo', function() {
return 'bar';
}, true);
```
#### instance array mixin
```php
Example::mixin([
'foo' => function() {
return 'bar';
}
], true);
```
#### instance method call
```php
$example = new Example;
Example->foo(); # 'bar'
```
## License
[MIT](http://opensource.org/licenses/MIT)