// Creating an event instance $buttonClick = new Event('click'); // Adding an event listener $buttonClick->addListener(function() { // Code to perform action });
// Creating an event dispatcher $dispatcher = new EventDispatcher(); // Triggering an event $dispatcher->dispatch(new Event('button.click'));
// Creating a custom event type class UserLoggedInEvent extends Event { public function __construct($user) { parent::__construct('user.loggedin'); $this->user = $user; } } // Triggering a custom event $dispatcher->dispatch(new UserLoggedInEvent($user));The Event instance and related classes are typically part of an event handling library or package, such as the Symfony EventDispatcher component or the Laravel Event system.