GemberPHP /
event-sourcing
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gember\EventSourcing\Resolver\DomainCommand; |
||
| 6 | |||
| 7 | use Gember\EventSourcing\Resolver\Common\DomainTag\DomainTagDefinition; |
||
| 8 | use Gember\EventSourcing\Util\Serialization\Serializable; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @phpstan-import-type DomainTagDefinitionPayload from DomainTagDefinition |
||
| 12 | * |
||
| 13 | * @phpstan-type DomainCommandDefinitionPayload array{ |
||
| 14 | * commandClassName: class-string, |
||
| 15 | * domainTags: list<DomainTagDefinitionPayload> |
||
| 16 | * } |
||
| 17 | * |
||
| 18 | * @implements Serializable<DomainCommandDefinitionPayload, DomainCommandDefinition> |
||
| 19 | */ |
||
| 20 | final readonly class DomainCommandDefinition implements Serializable |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param class-string $commandClassName |
||
| 24 | * @param list<DomainTagDefinition> $domainTags |
||
| 25 | */ |
||
| 26 | 7 | public function __construct( |
|
| 27 | public string $commandClassName, |
||
| 28 | public array $domainTags, |
||
| 29 | 7 | ) {} |
|
| 30 | |||
| 31 | 3 | public function toPayload(): array |
|
| 32 | { |
||
| 33 | 3 | return [ |
|
| 34 | 3 | 'commandClassName' => $this->commandClassName, |
|
| 35 | 3 | 'domainTags' => array_map(fn($domainTag) => $domainTag->toPayload(), $this->domainTags), |
|
| 36 | 3 | ]; |
|
| 37 | } |
||
| 38 | |||
| 39 | 3 | public static function fromPayload(array $payload): self |
|
| 40 | { |
||
| 41 | 3 | return new self( |
|
| 42 | 3 | $payload['commandClassName'], |
|
| 43 | 3 | array_map(fn($domainTagPayload) => DomainTagDefinition::fromPayload($domainTagPayload), $payload['domainTags']), |
|
| 44 | 3 | ); |
|
| 45 | } |
||
| 46 | } |
||
| 47 |