Skip to content

Commit 682e435

Browse files
author
Jeroen de Graaf
committed
Add all contracts for gember/event-sourcing
1 parent e78a731 commit 682e435

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\EventStore\Rdbms;
6+
7+
use DateTimeImmutable;
8+
9+
final readonly class RdbmsEvent
10+
{
11+
/**
12+
* @param list<string> $domainTags
13+
* @param array<string, mixed> $metadata
14+
*/
15+
public function __construct(
16+
public string $eventId,
17+
public array $domainTags,
18+
public string $eventName,
19+
public string $payload,
20+
public array $metadata,
21+
public DateTimeImmutable $appliedAt,
22+
) {}
23+
24+
public function withDomainTag(string $domainTag): self
25+
{
26+
return new self(
27+
$this->eventId,
28+
[...$this->domainTags, $domainTag],
29+
$this->eventName,
30+
$this->payload,
31+
$this->metadata,
32+
$this->appliedAt,
33+
);
34+
}
35+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\EventStore\Rdbms;
6+
7+
use Stringable;
8+
9+
interface RdbmsEventStoreRepository
10+
{
11+
/**
12+
* @param list<string|Stringable> $domainTags
13+
* @param list<string> $eventNames
14+
*
15+
* @return list<RdbmsEvent>
16+
*/
17+
public function getEvents(array $domainTags, array $eventNames): array;
18+
19+
/**
20+
* @param list<string|Stringable> $domainTags
21+
* @param list<string> $eventNames
22+
*/
23+
public function getLastEventIdPersisted(array $domainTags, array $eventNames): ?string;
24+
25+
/**
26+
* @param list<RdbmsEvent> $events
27+
*/
28+
public function saveEvents(array $events): void;
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\Util\Generator\Identity;
6+
7+
interface IdentityGenerator
8+
{
9+
public function generate(): string;
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\Util\Messaging\MessageBus;
6+
7+
interface EventBus
8+
{
9+
/**
10+
* @throws HandlingMessageFailedException
11+
*/
12+
public function handle(object $event): void;
13+
}
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\Util\Messaging\MessageBus;
6+
7+
use Exception;
8+
use Throwable;
9+
10+
final class HandlingMessageFailedException extends Exception
11+
{
12+
public static function withException(Throwable $exception): self
13+
{
14+
return new self(
15+
sprintf('Handling message failed: %s', $exception->getMessage()),
16+
previous: $exception,
17+
);
18+
}
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\Util\Serialization\Serializer;
6+
7+
use Exception;
8+
use Throwable;
9+
10+
class SerializationFailedException extends Exception
11+
{
12+
public static function withMessage(string $message): self
13+
{
14+
return new self(sprintf('Serialization failed: %s', $message));
15+
}
16+
17+
public static function withException(Throwable $exception): self
18+
{
19+
return new self(
20+
sprintf('Serialization failed: %s', $exception->getMessage()),
21+
previous: $exception,
22+
);
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gember\DependencyContracts\Util\Serialization\Serializer;
6+
7+
interface Serializer
8+
{
9+
/**
10+
* @throws SerializationFailedException
11+
*/
12+
public function serialize(object $object): string;
13+
14+
/**
15+
* @param class-string $className
16+
*
17+
* @throws SerializationFailedException
18+
*/
19+
public function deserialize(string $payload, string $className): object;
20+
}

0 commit comments

Comments
 (0)