userId = $userId; } public function getUserId() { return $this->userId; } } class UserCreatedListener implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ UserEvent::CREATED => 'onUserCreated' ]; } public function onUserCreated(UserEvent $event) { echo "User {$event->getUserId()} has been created!"; } } $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new UserCreatedListener()); $userEvent = new UserEvent(1001); $dispatcher->dispatch(UserEvent::CREATED, $userEvent);In this example, we defined two classes: `UserEvent` and `UserCreatedListener`. The `UserEvent` class defines two constants for the events: `CREATED` and `DELETED`. It also has a method to retrieve the user ID. The `UserCreatedListener` class implements the `EventSubscriberInterface` and defines the `getSubscribedEvents()` method to indicate which events it will listen to. It also defines the `onUserCreated()` method, which will be executed when a UserEvent is triggered. We create an instance of the `EventDispatcher` class and register the `UserCreatedListener` with it. Then we create a new instance of the `UserEvent` class with the user ID of 1001 and dispatch the `UserEvent::CREATED` event. The event listener will then execute the `onUserCreated()` method and print out the message, "User 1001 has been created!" The package library used in this example is the Symfony Event Dispatcher.