use EventRun\EventDispatcher; $dispatcher = new EventDispatcher(); $dispatcher->addListener('user.login', 'myLoginHandler'); function myLoginHandler($event) { // Code to execute when a user logs in } $dispatcher->dispatch('user.login');
use EventRun\EventDispatcher; use EventRun\Event; $dispatcher = new EventDispatcher(); function onFileUpload(Event $event) { // Code to execute when a file is uploaded } $dispatcher->addListener('file.upload', 'onFileUpload'); // Upload the file and trigger the event $filename = 'myfile.txt'; $dispatcher->dispatch('file.upload', new Event(['filename' => $filename]));In this example, we create an event dispatcher and add a listener for the 'file.upload' event. When this event is dispatched, the 'onFileUpload' function is called with the event object as its argument. We then upload a file and trigger the 'file.upload' event with the filename as an event parameter. Package Library: PHP Event Run is a standalone library that can be installed using Composer. Its package library name is "event-run/event-run".