The Event Dispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them asynchronously.
This package can be installed with Composer.
$ composer require nuxed/event-dispatcher
use namespace Nuxed\EventDispatcher;
use namespace Nuxed\EventDispatcher\ListenerProvider;
<<__EntryPoint>>
async function main(): Awaitable<void> {
$provider = new ListenerProvider\AttachableListenerProvider();
$provider->listen<SomeEvent>(new SomeEventListener());
$provider->listen<SomeOtherEvent>(new SomeOtherEventListener());
$dispatcher = new EventDispatcher\EventDispatcher($provider);
// dispatch multiple event listeners concurrently
concurrent {
// returns the event that was passed, now modified by listeners.
$someEvent = await $dispatcher->dispatch<SomeEvent>(new SomeEvent());
$someOtherEvent = await $dispatcher->dispatch<SomeOtherEvent>(new SomeOtherEvent());
}
}
For information on reporting security vulnerabilities in Nuxed, see SECURITY.md.
Nuxed is open-sourced software licensed under the MIT-licensed.