Skip to content

Commit

Permalink
full list of changes below:
Browse files Browse the repository at this point in the history
- check if aggregate supports given command
- check if listener supports given query
  • Loading branch information
alanbem committed Aug 15, 2021
1 parent 6281b92 commit b173838
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Domain/Command/Handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Streak\Domain\Command;

use Streak\Domain\AggregateRoot;
use Streak\Domain\Command;
use Streak\Domain\Exception\CommandNotSupported;

Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Query/Handling.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Streak\Domain\Query;

use Streak\Domain\Event;
use Streak\Domain\Exception\QueryNotSupported;
use Streak\Domain\Query;

Expand All @@ -25,6 +26,12 @@ trait Handling
{
public function handleQuery(Query $query)
{
if ($query instanceof EventListenerQuery and $this instanceof Event\Listener) {
if (false === $this->listenerId()->equals($query->listenerId())) {
throw new QueryNotSupported($query);
}
}

$reflection = new \ReflectionObject($this);

foreach ($reflection->getMethods() as $method) {
Expand Down

0 comments on commit b173838

Please sign in to comment.