Skip to content

Commit cf944ae

Browse files
committed
full list of changes below:
- check if aggregate supports given command - check if listener supports given query
1 parent 8ba1a1f commit cf944ae

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Domain/Command/Handling.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Streak\Domain\Command;
1515

16+
use Streak\Domain\AggregateRoot;
1617
use Streak\Domain\Command;
1718
use Streak\Domain\Exception\CommandNotSupported;
1819

@@ -25,6 +26,12 @@ trait Handling
2526
{
2627
public function handleCommand(Command $command): void
2728
{
29+
if ($command instanceof AggregateRootCommand && $this instanceof AggregateRoot) {
30+
if (false === $this->aggregateRootId()->equals($command->aggregateRootId())) {
31+
throw new CommandNotSupported($command);
32+
}
33+
}
34+
2835
$reflection = new \ReflectionObject($this);
2936

3037
foreach ($reflection->getMethods() as $method) {

src/Domain/Query/Handling.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Streak\Domain\Query;
1515

16+
use Streak\Domain\Event;
1617
use Streak\Domain\Exception\QueryNotSupported;
1718
use Streak\Domain\Query;
1819

@@ -25,6 +26,12 @@ trait Handling
2526
{
2627
public function handleQuery(Query $query)
2728
{
29+
if ($query instanceof EventListenerQuery && $this instanceof Event\Listener) {
30+
if (false === $this->listenerId()->equals($query->listenerId())) {
31+
throw new QueryNotSupported($query);
32+
}
33+
}
34+
2835
$reflection = new \ReflectionObject($this);
2936

3037
foreach ($reflection->getMethods() as $method) {

0 commit comments

Comments
 (0)