-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91dabc1
commit 1a995c2
Showing
20 changed files
with
351 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
namespace Patchlevel\EventSourcing\Message\Translator; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateHeader; | ||
use Patchlevel\EventSourcing\Message\HeaderNotFound; | ||
use Patchlevel\EventSourcing\Message\Message; | ||
use Patchlevel\EventSourcing\Store\StreamHeader; | ||
use Patchlevel\EventSourcing\Store\Header\PlayheadHeader; | ||
use Patchlevel\EventSourcing\Store\Header\StreamNameHeader; | ||
|
||
use function array_key_exists; | ||
|
||
|
@@ -19,42 +19,30 @@ final class RecalculatePlayheadTranslator implements Translator | |
/** @return list<Message> */ | ||
public function __invoke(Message $message): array | ||
{ | ||
try { | ||
$header = $message->header(AggregateHeader::class); | ||
} catch (HeaderNotFound) { | ||
try { | ||
$header = $message->header(StreamHeader::class); | ||
} catch (HeaderNotFound) { | ||
return [$message]; | ||
} | ||
} | ||
if ($message->hasHeader(StreamNameHeader::class) && $message->hasHeader(PlayheadHeader::class)) { | ||
Check warning on line 22 in src/Message/Translator/RecalculatePlayheadTranslator.php GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)
Check warning on line 22 in src/Message/Translator/RecalculatePlayheadTranslator.php GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)
Check warning on line 22 in src/Message/Translator/RecalculatePlayheadTranslator.php GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)
|
||
$streamName = $message->header(StreamNameHeader::class)->streamName; | ||
|
||
$stream = $header instanceof StreamHeader ? $header->streamName : $header->streamName(); | ||
$playhead = $this->nextPlayhead($streamName); | ||
|
||
$playhead = $this->nextPlayhead($stream); | ||
|
||
if ($header->playhead === $playhead) { | ||
return [$message]; | ||
return [ | ||
$message->withHeader(new PlayheadHeader($playhead)), | ||
]; | ||
} | ||
|
||
if ($header instanceof StreamHeader) { | ||
if ($message->hasHeader(AggregateHeader::class)) { | ||
$header = $message->header(AggregateHeader::class); | ||
|
||
return [ | ||
$message->withHeader(new StreamHeader( | ||
$header->streamName, | ||
$playhead, | ||
$message->withHeader(new AggregateHeader( | ||
$header->aggregateName, | ||
$header->aggregateId, | ||
$this->nextPlayhead($header->streamName()), | ||
$header->recordedOn, | ||
)), | ||
]; | ||
} | ||
|
||
return [ | ||
$message->withHeader(new AggregateHeader( | ||
$header->aggregateName, | ||
$header->aggregateId, | ||
$playhead, | ||
$header->recordedOn, | ||
)), | ||
]; | ||
return [$message]; | ||
} | ||
|
||
public function reset(): void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Header; | ||
|
||
/** | ||
* @psalm-immutable | ||
* @experimental | ||
*/ | ||
final class PlayheadHeader | ||
{ | ||
/** @param positive-int $playhead */ | ||
public function __construct( | ||
public readonly int $playhead, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Header; | ||
|
||
use DateTimeImmutable; | ||
|
||
/** | ||
* @psalm-immutable | ||
* @experimental | ||
*/ | ||
final class RecordedOnHeader | ||
{ | ||
public function __construct( | ||
public readonly DateTimeImmutable $recordedOn, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Store\Header; | ||
|
||
/** | ||
* @psalm-immutable | ||
* @experimental | ||
*/ | ||
final class StreamNameHeader | ||
{ | ||
public function __construct( | ||
public readonly string $streamName, | ||
) { | ||
} | ||
} |
Oops, something went wrong.