From cf944ae479ce9acfa43f261336706d9882061579 Mon Sep 17 00:00:00 2001 From: Alan Gabriel Bem Date: Sun, 15 Aug 2021 17:43:55 +0200 Subject: [PATCH] full list of changes below: - check if aggregate supports given command - check if listener supports given query --- src/Domain/Command/Handling.php | 7 +++++++ src/Domain/Query/Handling.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Domain/Command/Handling.php b/src/Domain/Command/Handling.php index b04abaf2..f0b002f4 100644 --- a/src/Domain/Command/Handling.php +++ b/src/Domain/Command/Handling.php @@ -13,6 +13,7 @@ namespace Streak\Domain\Command; +use Streak\Domain\AggregateRoot; use Streak\Domain\Command; use Streak\Domain\Exception\CommandNotSupported; @@ -25,6 +26,12 @@ trait Handling { public function handleCommand(Command $command): void { + if ($command instanceof AggregateRootCommand && $this instanceof AggregateRoot) { + if (false === $this->aggregateRootId()->equals($command->aggregateRootId())) { + throw new CommandNotSupported($command); + } + } + $reflection = new \ReflectionObject($this); foreach ($reflection->getMethods() as $method) { diff --git a/src/Domain/Query/Handling.php b/src/Domain/Query/Handling.php index 390b9da7..2f810b4b 100644 --- a/src/Domain/Query/Handling.php +++ b/src/Domain/Query/Handling.php @@ -13,6 +13,7 @@ namespace Streak\Domain\Query; +use Streak\Domain\Event; use Streak\Domain\Exception\QueryNotSupported; use Streak\Domain\Query; @@ -25,6 +26,12 @@ trait Handling { public function handleQuery(Query $query) { + if ($query instanceof EventListenerQuery && $this instanceof Event\Listener) { + if (false === $this->listenerId()->equals($query->listenerId())) { + throw new QueryNotSupported($query); + } + } + $reflection = new \ReflectionObject($this); foreach ($reflection->getMethods() as $method) {