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) {