Skip to content

Commit

Permalink
Added second bool argument $apply in the method `AggregateRootTrait…
Browse files Browse the repository at this point in the history
…::recordThat()`
  • Loading branch information
tg666 committed Jan 10, 2024
1 parent 9ba7e0e commit e45589f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/ArchitectureBundle/Domain/AggregateRootTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ArchitectureBundle/Domain/DeletableAggregateRootTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e45589f

Please sign in to comment.