-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Nuxed\EventDispatcher\Event; | ||
|
||
/** | ||
* Marker interface indicating an event instance. | ||
* | ||
* Event instances may contain zero methods, or as many methods as they | ||
* want. The interface MUST be implemented, however, to provide type-safety | ||
* to both listeners as well as the dispatcher. | ||
*/ | ||
interface IEvent {} |
22 changes: 22 additions & 0 deletions
22
src/Nuxed/Contract/EventDispatcher/Event/IStoppableEvent.hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Nuxed\EventDispatcher\Event; | ||
|
||
/** | ||
* An Event whose processing may be interrupted when the event has been handled. | ||
* | ||
* A Dispatcher implementation MUST check to determine an Event | ||
* is marked as stopped after each listener is called. If it is then it should | ||
* return immediately without calling any further Listeners. | ||
*/ | ||
interface IStoppableEvent extends IEvent { | ||
/** | ||
* Is propagation stopped? | ||
* | ||
* This will typically only be used by the Dispatcher to determine if the | ||
* previous listener halted propagation. | ||
* | ||
* @return bool | ||
* True if the Event is complete and no further listeners should be called. | ||
* False to continue calling listeners. | ||
*/ | ||
public function isPropagationStopped(): bool; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Nuxed/Contract/EventDispatcher/EventListener/IEventListener.hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Nuxed\EventDispatcher\EventListener; | ||
|
||
use namespace Nuxed\EventDispatcher\Event; | ||
|
||
/** | ||
* Defines a listener for an event. | ||
*/ | ||
interface IEventListener<T as Event\IEvent> { | ||
/** | ||
* Process the given event. | ||
*/ | ||
public function process(T $event): Awaitable<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Nuxed\EventDispatcher; | ||
|
||
/** | ||
* Defines a dispatcher for events. | ||
*/ | ||
interface IEventDispatcher { | ||
/** | ||
* Provide all relevant listeners with an event to process. | ||
* | ||
* @template T as IEvent | ||
* | ||
* @return T The Event that was passed, now modified by listeners. | ||
*/ | ||
public function dispatch<T as Event\IEvent>(T $event): Awaitable<T>; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Nuxed/Contract/EventDispatcher/ListenerProvider/IListenerProvider.hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Nuxed\EventDispatcher\ListenerProvider; | ||
|
||
use namespace Nuxed\EventDispatcher\{Event, EventListener}; | ||
|
||
/** | ||
* Mapper from an event to the listeners that are applicable to that event. | ||
*/ | ||
interface IListenerProvider { | ||
/** | ||
* Retrieve all listeners for the given event. | ||
* | ||
* @param T $event | ||
* An event for which to return the relevant listeners. | ||
* @return AsyncIterator<EventListener\IEventListener<T>> | ||
* An async iterator (usually an async generator) of listeners. Each | ||
* listener MUST be type-compatible with $event. | ||
*/ | ||
public function getListeners<T as Event\IEvent>( | ||
T $event, | ||
): AsyncIterator<EventListener\IEventListener<T>>; | ||
} |