Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved command and query handling #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && $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