Skip to content

Feat/event sender#19

Merged
gwillz merged 8 commits into
masterfrom
feat/event-sender
Jun 2, 2026
Merged

Feat/event sender#19
gwillz merged 8 commits into
masterfrom
feat/event-sender

Conversation

@gwillz

@gwillz gwillz commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

The event system was a little rushed when we first wrote it. This polishes a few part of the events system that should have been done long ago.

Events are largely emitted from static interfaces, which makes the sender property a bit weird and the EventableTrait rather misleading for a few behaviours. In particularly using $inst->on(...) would receive events from other instances which is very odd (and annoying).

Events could also be triggered for other classes by using $this->trigger(OtherClass::class) which is clearly incorrect usage.

The handled property was odd. It's baked into the base event class but requires each handler to check? Very silly. This is probably the most likely breaking change in this PR.

Whereas the rest of the changes are bugfixes because no-one should be expecting those behaviours to work as they were. If their workflow break? Well good.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines the static event system to better support instance-scoped listeners (via object senders) and centralizes “handled” short-circuiting inside the dispatcher, addressing previously confusing/incorrect behaviors around sender identity and cross-instance event delivery.

Changes:

  • Add support for passing an object as the $sender in Events::trigger()/Events::on()/Events::off() to enable instance-scoped listener registration.
  • Stop dispatching additional handlers once an Event marks itself as handled.
  • Update tests to reflect the new handled semantics and to verify per-instance sender behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/Events.php Extends sender handling to accept objects, sets sender on events, and stops dispatch after handled; updates listener registration to support instance-scoped filtering.
src/EventableTrait.php Adjusts instance helper methods to register listeners against the instance and restrict triggering against unrelated classes.
tests/EventTest.php Updates handled expectations and adds coverage for instance-specific sender behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/EventableTrait.php Outdated
Comment thread src/Events.php
Comment thread src/Events.php
gwillz added 4 commits June 1, 2026 13:10
Although Event is abstract, this is valid and would work:

Events::on($instance, SomeEvent::class, function(Event $event) {});
Events::trigger($instance, new SomeEvent());
@gwillz gwillz merged commit e704d8e into master Jun 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants