Fixed message parsing bug

This commit is contained in:
2024-03-01 21:48:28 +01:00
parent c4f3e8ae50
commit b2494c3163
3 changed files with 25 additions and 5 deletions

View File

@ -66,6 +66,11 @@ class Message implements JsonSerializable
return new Message($json['msg'], $json['data'], $json['uuid']??false);
}
public static function fromStringMulti(string $data): array
{
return array_map(fn($v) => Message::fromString($v), array_filter(explode("\n", $data)));
}
public function asResult($result): Message
{
return new Message(self::MSGTYPE_RESULT, [
@ -73,6 +78,13 @@ class Message implements JsonSerializable
], $this->uuid);
}
public function asError($error): Message
{
return new Message(self::MSGTYPE_ERROR, [
'error' => $error
], $this->uuid);
}
public function toJson(): string
{
return json_encode($this, JSON_UNESCAPED_SLASHES);