uuid = $data['uuid']; $this->channelUuid = $data['channel_uuid']; $this->recipient = CommunicationRecipientType::from($data['recipient']); $this->message = $data['message']; $this->signature = $data['signature']; $this->received = (bool)$data['received']; if($data['timestamp'] instanceof DateTime) { $this->timestamp = $data['timestamp']; } elseif(is_int($data['timestamp'])) { $this->timestamp = (new DateTime())->setTimestamp($data['timestamp']); } elseif(is_string($data['timestamp'])) { $this->timestamp = new DateTime($data['timestamp']); } else { throw new InvalidArgumentException('Invalid timestamp type, got ' . gettype($data['timestamp'])); } } /** * Returns the unique identifier for the message. * * @return string */ public function getUuid(): string { return $this->uuid; } /** * Returns the UUID of the channel that the message belongs to. * * @return string */ public function getChannelUuid(): string { return $this->channelUuid; } /** * Returns the recipient type of the message. * * @return CommunicationRecipientType */ public function getRecipient(): CommunicationRecipientType { return $this->recipient; } /** * Returns the message content. * * @return string */ public function getMessage(): string { return $this->message; } /** * Returns the signature of the message. * * @return string */ public function getSignature(): string { return $this->signature; } /** * Returns whether the message has been received. * * @return bool */ public function isReceived(): bool { return $this->received; } /** * Returns the timestamp of the message. * * @return DateTime */ public function getTimestamp(): DateTime { return $this->timestamp; } /** * @inheritDoc */ public static function fromArray(array $data): ChannelMessageRecord { return new self($data); } /** * @inheritDoc */ public function toArray(): array { return [ 'uuid' => $this->uuid, 'channel_uuid' => $this->channelUuid, 'recipient' => $this->recipient->value, 'message' => $this->message, 'signature' => $this->signature, 'received' => $this->received, 'timestamp' => $this->timestamp->format('Y-m-d H:i:s') ]; } public function toStandard(): EncryptionChannelMessage { return new EncryptionChannelMessage($this->toArray()); } }