diff --git a/src/Kernel/ContextResponseInterface.php b/src/Kernel/ContextResponseInterface.php index 82ad01a..4c8c487 100644 --- a/src/Kernel/ContextResponseInterface.php +++ b/src/Kernel/ContextResponseInterface.php @@ -32,16 +32,19 @@ public function setData(array $data): self; public function getData(): array; /** - * Add a domain event. + * Add an event, classified by its publication scope. */ - public function addEvent(object $event): self; + public function addEvent(object $event, EventScope $scope = EventScope::Internal): self; /** * Get events from this result, keyed by context name. * + * Without a scope, returns all events (structurally unchanged). With a + * scope, returns only the events of that scope. + * * @return array> */ - public function getEvents(): array; + public function getEvents(?EventScope $scope = null): array; /** * Add an error message. diff --git a/src/Kernel/DomainResponseInterface.php b/src/Kernel/DomainResponseInterface.php index ad32ff3..ed5699d 100644 --- a/src/Kernel/DomainResponseInterface.php +++ b/src/Kernel/DomainResponseInterface.php @@ -32,9 +32,12 @@ public function getData(): array; /** * Get all collected domain events, keyed by context name. * + * Without a scope, returns all events (structurally unchanged). With a + * scope, returns only the events of that scope. + * * @return array> */ - public function getEvents(): array; + public function getEvents(?EventScope $scope = null): array; /** * Get all errors, keyed by context name. diff --git a/src/Kernel/EventScope.php b/src/Kernel/EventScope.php new file mode 100644 index 0000000..a73dfca --- /dev/null +++ b/src/Kernel/EventScope.php @@ -0,0 +1,18 @@ +