diff --git a/src/ArchitectureBundle/Domain/AggregateRootTrait.php b/src/ArchitectureBundle/Domain/AggregateRootTrait.php index 116a4e5..12e89df 100644 --- a/src/ArchitectureBundle/Domain/AggregateRootTrait.php +++ b/src/ArchitectureBundle/Domain/AggregateRootTrait.php @@ -53,12 +53,14 @@ protected function apply(AbstractDomainEvent $event): void $this->{$handler}($event); } - protected function recordThat(AbstractDomainEvent $event): void + protected function recordThat(AbstractDomainEvent $event, bool $apply = true): void { ++$this->version; $this->recordedEvents[] = $event->withVersion($this->version); - $this->apply($event); + if ($apply) { + $this->apply($event); + } } protected function determineEventHandlerMethodFor(AbstractDomainEvent $event): string diff --git a/src/ArchitectureBundle/Domain/DeletableAggregateRootTrait.php b/src/ArchitectureBundle/Domain/DeletableAggregateRootTrait.php index bdbdb55..73c177b 100644 --- a/src/ArchitectureBundle/Domain/DeletableAggregateRootTrait.php +++ b/src/ArchitectureBundle/Domain/DeletableAggregateRootTrait.php @@ -17,13 +17,13 @@ trait DeletableAggregateRootTrait protected ?DateTimeImmutable $deletedAt = null; - protected function recordThat(AbstractDomainEvent $event): void + protected function recordThat(AbstractDomainEvent $event, bool $apply = true): void { if ($this->isDeleted()) { throw UnableToRecordEventOnDeletedAggregateException::create(static::class, $this->getAggregateId()); } - $this->_recordThat($event); + $this->_recordThat($event, $apply); } public function isDeleted(): bool