|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Akinoriakatsuka\CqrsEsExamplePhp\Command\Domain\Events; |
| 4 | + |
| 5 | +use Akinoriakatsuka\CqrsEsExamplePhp\Command\Domain\Models\GroupChatId; |
| 6 | +use Akinoriakatsuka\CqrsEsExamplePhp\Command\Domain\Models\MessageId; |
| 7 | +use Akinoriakatsuka\CqrsEsExamplePhp\Command\Domain\Models\UserAccountId; |
| 8 | +use DateTimeImmutable; |
| 9 | + |
| 10 | +readonly class GroupChatMessageEdited implements GroupChatEvent { |
| 11 | + private string $id; |
| 12 | + private GroupChatId $groupChatId; |
| 13 | + private MessageId $messageId; |
| 14 | + private string $newText; |
| 15 | + private UserAccountId $executorId; |
| 16 | + private int $sequenceNumber; |
| 17 | + private DateTimeImmutable $occurredAt; |
| 18 | + |
| 19 | + public function __construct( |
| 20 | + string $id, |
| 21 | + GroupChatId $groupChatId, |
| 22 | + MessageId $messageId, |
| 23 | + string $newText, |
| 24 | + UserAccountId $executorId, |
| 25 | + int $sequenceNumber, |
| 26 | + DateTimeImmutable $occurredAt |
| 27 | + ) { |
| 28 | + $this->id = $id; |
| 29 | + $this->groupChatId = $groupChatId; |
| 30 | + $this->messageId = $messageId; |
| 31 | + $this->newText = $newText; |
| 32 | + $this->executorId = $executorId; |
| 33 | + $this->sequenceNumber = $sequenceNumber; |
| 34 | + $this->occurredAt = $occurredAt; |
| 35 | + } |
| 36 | + |
| 37 | + public function getId(): string { |
| 38 | + return $this->id; |
| 39 | + } |
| 40 | + |
| 41 | + public function getTypeName(): string { |
| 42 | + return 'group-chat-message-edited'; |
| 43 | + } |
| 44 | + |
| 45 | + public function getSequenceNumber(): int { |
| 46 | + return $this->sequenceNumber; |
| 47 | + } |
| 48 | + |
| 49 | + public function isCreated(): bool { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + public function getOccurredAt(): DateTimeImmutable { |
| 54 | + return $this->occurredAt; |
| 55 | + } |
| 56 | + |
| 57 | + public function getAggregateId(): GroupChatId { |
| 58 | + return $this->groupChatId; |
| 59 | + } |
| 60 | + |
| 61 | + public function getMessageId(): MessageId { |
| 62 | + return $this->messageId; |
| 63 | + } |
| 64 | + |
| 65 | + public function getNewText(): string { |
| 66 | + return $this->newText; |
| 67 | + } |
| 68 | + |
| 69 | + public function getExecutorId(): UserAccountId { |
| 70 | + return $this->executorId; |
| 71 | + } |
| 72 | + |
| 73 | + public function jsonSerialize(): mixed { |
| 74 | + return [ |
| 75 | + 'id' => $this->id, |
| 76 | + 'type' => $this->getTypeName(), |
| 77 | + 'groupChatId' => $this->groupChatId, |
| 78 | + 'messageId' => $this->messageId, |
| 79 | + 'newText' => $this->newText, |
| 80 | + 'executorId' => $this->executorId, |
| 81 | + 'sequenceNumber' => $this->sequenceNumber, |
| 82 | + 'occurredAt' => $this->occurredAt->format(DATE_ATOM), |
| 83 | + ]; |
| 84 | + } |
| 85 | +} |
0 commit comments