phpzend-frameworksymfonyobserver-patternevent-dispatching

What's the best way to integrate an event-dispatcher in a PHP library?


I need to integrate an event dispatcher in my own codebase (custom PHP library), so I looked at what both Symfony2 and Zend Framework 2 are doing.

Obviously, there's no shared interface for dispatching events, because both frameworks have different needs and decided to implement their own code... so I am a bit lost: I don't want to reinvent my personal wheel.

Probably the SPL interfaces for implementing the observer pattern are a bit naive, so I'm here asking you: what would you do?

EDIT

Since it's not clear... I want to re-use an existing ED, letting the developer inject it in my library.

Let's say you develop a lib with a dispatcher and you know that your lib is gonna be a part of a Symfony Bundle and also re-used in ZF projects: you surely want to re-use Symfony's and ZF dispatchers, instead of your own.

Therefore I was looking for shared interfaces for existing dispatchers implemented in mainstream libraries, but sounds like there's no solution.


Solution

  • You could define an interface for your needs and then implements it with differents adapters for each framework.