igorw/evenement — pull request #17 by ihabunek (2014-02-04 13:02:30+00:00)
Title: Implemented a static event emitter

I have a use case where i need static calls to the event emitter.

This PR provides a trait which provides all the EventEmitter methods statically.

The solution uses __callStatic to forward calls to an instance of EventEmitter. This prevents any code duplication, since the StaticEventEmitterTrait does not need to be changed when EventEmitter is changed. There is a performance hit, but it's not that bad.

I did some performance testing (https://gist.github.com/ihabunek/8803125). And for 100 listeners, and 100k events, the results are:

```
Dynamic adding: 0
Dynamic emitting: 4.2352
--
Static adding: 0.001
Static emitting: 4.3292
```

Also, the performance hit can be mitigated by using:
```
MyEmitter::emitter()->on(...);
```
instead of the shorter version which invokes __callStatic:
```
MyEmitter::on(...);
```