Skip to content

Commit 6e962f1

Browse files
Jeroen de Graafjerowork
authored andcommitted
Setup contract for Saga repository handling
1 parent 41e8b83 commit 6e962f1

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/EventStore/Saga/RdbmsSaga.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\EventStore\Saga;
6+
7+
use Stringable;
8+
use DateTimeImmutable;
9+
10+
final readonly class RdbmsSaga
11+
{
12+
public function __construct(
13+
public string $sagaName,
14+
public string|Stringable $sagaId,
15+
public string $payload,
16+
public DateTimeImmutable $createdAt,
17+
public ?DateTimeImmutable $updatedAt,
18+
) {}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\EventStore\Saga;
6+
7+
use Exception;
8+
use Stringable;
9+
10+
final class RdbmsSagaNotFoundException extends Exception
11+
{
12+
public static function withSagaId(string $sagaName, string|Stringable $sagaId): self
13+
{
14+
return new self(sprintf("Saga '%s' with id %s not found in SagaStore", $sagaName, $sagaId));
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\EventStore\Saga;
6+
7+
use Stringable;
8+
use DateTimeImmutable;
9+
10+
interface RdbmsSagaStoreRepository
11+
{
12+
/**
13+
* @throws RdbmsSagaNotFoundException
14+
*/
15+
public function get(string $sagaName, string|Stringable $sagaId): RdbmsSaga;
16+
17+
/**
18+
* @param array<string, mixed> $metadata
19+
*/
20+
public function save(
21+
string $sagaName,
22+
string|Stringable $sagaId,
23+
string $payload,
24+
array $metadata,
25+
DateTimeImmutable $now,
26+
): RdbmsSaga;
27+
}

0 commit comments

Comments
 (0)