-
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
e3da365
commit bf9fcc3
Showing
16 changed files
with
219 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ deptrac: | |
- Metadata | ||
- Subscription | ||
Subscription: | ||
- Aggregate | ||
- Attribute | ||
- Clock | ||
- Message | ||
|
23 changes: 23 additions & 0 deletions
23
src/Subscription/Subscriber/ArgumentResolver/AggregateIdArgumentResolver.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateHeader; | ||
use Patchlevel\EventSourcing\Message\Message; | ||
|
||
use function in_array; | ||
|
||
final class AggregateIdArgumentResolver implements ArgumentResolver | ||
{ | ||
public function resolve(Argument $argument, Message $message): string | ||
{ | ||
return $message->header(AggregateHeader::class)->aggregateId; | ||
} | ||
|
||
public function support(Argument $argument, string $eventClass): bool | ||
{ | ||
return $argument->type === 'string' && in_array($argument->name, ['aggregateId', 'aggregateRootId']); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
final class Argument | ||
{ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly string $type, | ||
) { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Subscription/Subscriber/ArgumentResolver/ArgumentResolver.php
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Message\Message; | ||
|
||
interface ArgumentResolver | ||
{ | ||
public function resolve(Argument $argument, Message $message): mixed; | ||
|
||
public function support(Argument $argument, string $eventClass): bool; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Subscription/Subscriber/ArgumentResolver/EventArgumentResolver.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Message\Message; | ||
|
||
use function class_exists; | ||
use function is_a; | ||
|
||
final class EventArgumentResolver implements ArgumentResolver | ||
{ | ||
public function resolve(Argument $argument, Message $message): object | ||
{ | ||
return $message->event(); | ||
} | ||
|
||
public function support(Argument $argument, string $eventClass): bool | ||
{ | ||
return class_exists($argument->type) && is_a($eventClass, $argument->type, true); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Subscription/Subscriber/ArgumentResolver/MessageArgumentResolver.php
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Message\Message; | ||
|
||
final class MessageArgumentResolver implements ArgumentResolver | ||
{ | ||
public function resolve(Argument $argument, Message $message): Message | ||
{ | ||
return $message; | ||
} | ||
|
||
public function support(Argument $argument, string $eventClass): bool | ||
{ | ||
return $argument->type === Message::class; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Subscription/Subscriber/ArgumentResolver/RecordedOnArgumentResolver.php
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use DateTimeImmutable; | ||
use Patchlevel\EventSourcing\Aggregate\AggregateHeader; | ||
use Patchlevel\EventSourcing\Message\Message; | ||
|
||
final class RecordedOnArgumentResolver implements ArgumentResolver | ||
{ | ||
public function resolve(Argument $argument, Message $message): DateTimeImmutable | ||
{ | ||
return $message->header(AggregateHeader::class)->recordedOn; | ||
} | ||
|
||
public function support(Argument $argument, string $eventClass): bool | ||
{ | ||
return $argument->type === DateTimeImmutable::class; | ||
} | ||
} |
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
Oops, something went wrong.