The EventEmitter is a simple pattern that allows you to create an object that emits events, and allow you to listen to those events.
composer require jbzoo/event
use JBZoo\Event\EventManager;
$eManager = new EventManager();
// Simple
$eManager->on('create', function () {
echo "Something action";
});
// Just do it!
$eManager->trigger('create');
By supplying a priority, you are ensured that subscribers handle in a specific order. The default priority is EventManager::MID. Anything below that will be triggered earlier, anything higher later. If there are two subscribers with the same priority, they will execute in an undefined, but deterministic order.
// Run it first
$eManager->on('create', function () {
echo "Something high priority action";
}, EventManager::HIGH);
// Run it latest
$eManager->on('create', function () {
echo "Something another action";
}, EventManager::LOW);
// Custom index
$eManager->on(