-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for outside listeners #145
base: main
Are you sure you want to change the base?
Conversation
Ugh. I accidentally ran |
What is the status on this? Is it currently possible to listen or subscribe to verb events outside of the event definition itself? In our case the event itself will be inaccessible to the developer writing projections in some cases, as it will be in another code base (composer package) handled by another team. In other words for some parts of the system we will have one development team publishing events and another team subscribing to them. |
As a workaround I'll be testing a POC using circular dependency. I.E.: // after apply()
public function handle()
{
$listeners = app(CustomerHandlers::class)->getListeners();
foreach ($listeners as $listener) {
$listener->handle($this);
}
} // meanwhile, somewhere in a whole 'nother code base ...
class SubscriptionHandler implements CustomerHandler
{
public function handle(Event $event): mixed
{
return match(get_class($event)) {
CustomerBeganTrial::class => Subscription::create([
'customer_id' => $event->customer_id,
'expires_at' => now()->addDays(30),
]),
default => null,
};
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This lets you register outside listeners for events. Say you have an analytics process, or some secondary reporting functionality that you want to add. Sometimes it doesn't make sense for those to exist on the event itself. Now you can do something like:
Then you just register with: