Over a million developers have joined DZone.
Platinum Partner

sabre-event, a simple event management library for PHP 5.4

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

I just released version 1.0 of sabre-event, a simple event management library for PHP, heavily inspired by both nodejs' EventEmitter, and Igor Wielder's Événement.

This library has a few extra features not in Événement that I really needed, and Igor had no plans adding it to his library, so I wrote my own.

In a nutshell, this is how you use it:


use Sabre\Event\EventEmitter;

include 'vendor/autoload.php';

$eventEmitter = new EventEmitter();

// subscribing
$eventEmitter->on('create', function() {

    echo "Something got created, apparently\n"




The EventEmitter object can also be integrated into existing objects, by extending it, or using it as a trait:


use Sabre\Event;

class MyNotUneventfulApplication implements Event\EventEmitterInterface

    use Event\EventEmitterTrait;



It differs from Événement in two features:

  1. It's possible to prioritize listeners, and let them trigger earlier or later in the event chain.
  2. It's possible for listeners to break the event chain, much like javascript's preventDefault().

I hope it will be useful to others. You can find the full documentation on GitHub, and the preferred installation method is through Composer.

The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


Published at DZone with permission of Evert Pot , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}