zippovich2 / event-dispatcher
Simple event dispatcher
v1.0.0
2020-06-03 11:40 UTC
Requires
- php: ^7.2.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2024-11-11 21:53:40 UTC
README
Simple event dispatcher.
Installation
$ composer require zippovich2/event-dispatcher
Usage
-
Default usage:
use Zippovich2\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher(); // Add subscriber to events $dispatcher->subscribe('event1', 'Subscriber::callback'); $dispatcher->subscribe('event2', 'Subscriber::callback2'); // Getting event subscribers $event1Subscribers = $dispatcher->getSubscribers('event1'); // Or get subscribers from all events $allSubscribers = $dispatcher->getSubscribers(); // Dispatch event $dispatcher->dispatch('eventName');
-
Using
TraceableEventDispatcher
:use Zippovich2\EventDispatcher\TraceableEventDispatcher; $dispatcher = new TraceableEventDispatcher(); // Add subscriber to events $dispatcher->subscribe('event1', 'Subscriber::callback'); $dispatcher->subscribe('event2', 'Subscriber::callback2'); // Dispatch event return callstack tree $callstackTree = $dispatcher->dispatch('eventName'); // Getting raw callstack $callStack = $dispatcher->getCallStack();