FastEventManager, only an event manager

01 Nov 2015 · One minute read · on Gianluca's blog

The Event-Driven Messaging is a design pattern, applied within the service-orientation design paradigm in order to enable the service consumers, which are interested in events that occur within the periphery of a service provider, to get notifications about these events as and when they occur without resorting to the traditional inefficientpolling based mechanism. by. wiki

In PHP there are different implementation of this pattern, but I tried to write my idea. An easy to understand and to extends event manager based on regex.

Why? Because it is a good way to match strings, it is flexible and powerful. As it is smart and little and it can be used as basis for custom implementation. it resolves a regex and triggers events It supports a priority to order triggered listeners.


composer require gianarb/fast-event-manager

Getting Started

require __DIR__."/vendor/autoload.php";
use GianArb\FastEventManager;
$eventManager = new FastEventManager();
$eventManager->attach("user_saved", function($event) {
$user = new Entity\User();
$eventManager->trigger("/user_saved/", $event);

Each listener has a priority (default = 0), it describe the order of execution

$eventManager->attach("wellcome", function() {
    echo " dev!";
}, 100);
$eventManager->attach("wellcome", function() {
    echo "Hello";
}, 345);
//output "Hello dev!"

I wrote this library because there are a lot of solutions that implement this pattern but they are verbose, this is only an event manager if you search other features you can extends it or you can use differents implementations. On top of this library you can write your library to build an event manager ready to use with your team in your applications.

This is a good solution because it is easy, ~31 line of code to trigger events without fear to inherit many line of codes and unused features to maintain.

Something weird with this website? Let me know.