Skip to content

Commit

Permalink
if no decorator is given, use RecordedOnDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed May 20, 2022
1 parent 496a919 commit 5fe169d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/Repository/DefaultRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use DateTimeImmutable;
use Patchlevel\EventSourcing\Aggregate\AggregateRoot;
use Patchlevel\EventSourcing\Clock\SystemClock;
use Patchlevel\EventSourcing\EventBus\Decorator\MessageDecorator;
use Patchlevel\EventSourcing\EventBus\Decorator\RecordedOnDecorator;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootMetadata;
Expand Down Expand Up @@ -37,7 +39,7 @@ final class DefaultRepository implements Repository
private ?SnapshotStore $snapshotStore;
private LoggerInterface $logger;
private AggregateRootMetadata $metadata;
private ?MessageDecorator $messageDecorator;
private MessageDecorator $messageDecorator;

/**
* @param class-string<T> $aggregateClass
Expand All @@ -54,7 +56,7 @@ public function __construct(
$this->eventBus = $eventBus;
$this->aggregateClass = $aggregateClass;
$this->snapshotStore = $snapshotStore;
$this->messageDecorator = $messageDecorator;
$this->messageDecorator = $messageDecorator ?? new RecordedOnDecorator(new SystemClock());
$this->logger = $logger ?? new NullLogger();
$this->metadata = $aggregateClass::metadata();
}
Expand Down Expand Up @@ -131,11 +133,7 @@ static function (object $event) use ($aggregate, &$playhead, $messageDecorator)
->withPlayhead(++$playhead)
->withRecordedOn(new DateTimeImmutable());

if ($messageDecorator) {
$message = $messageDecorator($message);
}

return $message;
return $messageDecorator($message);
},
$events
);
Expand Down
6 changes: 4 additions & 2 deletions src/Repository/DefaultRepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Patchlevel\EventSourcing\Repository;

use Patchlevel\EventSourcing\Aggregate\AggregateRoot;
use Patchlevel\EventSourcing\Clock\SystemClock;
use Patchlevel\EventSourcing\EventBus\Decorator\MessageDecorator;
use Patchlevel\EventSourcing\EventBus\Decorator\RecordedOnDecorator;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootClassNotRegistered;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
Expand All @@ -22,7 +24,7 @@ final class DefaultRepositoryManager implements RepositoryManager
private Store $store;
private EventBus $eventBus;
private ?SnapshotStore $snapshotStore;
private ?MessageDecorator $messageDecorator;
private MessageDecorator $messageDecorator;
private LoggerInterface $logger;

/** @var array<class-string<AggregateRoot>, Repository> */
Expand All @@ -40,7 +42,7 @@ public function __construct(
$this->store = $store;
$this->eventBus = $eventBus;
$this->snapshotStore = $snapshotStore;
$this->messageDecorator = $messageDecorator;
$this->messageDecorator = $messageDecorator ?? new RecordedOnDecorator(new SystemClock());
$this->logger = $logger ?? new NullLogger();
}

Expand Down

0 comments on commit 5fe169d

Please sign in to comment.