From 0ad263b1f09514cb94d1dce4bf17591fcc1d7cab Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 3 Sep 2024 12:35:31 -0400 Subject: [PATCH] Add RpcResponse class to handle RPC responses. --- src/Socialbox/Objects/RpcResponse.php | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/Socialbox/Objects/RpcResponse.php diff --git a/src/Socialbox/Objects/RpcResponse.php b/src/Socialbox/Objects/RpcResponse.php new file mode 100644 index 0000000..afabb7b --- /dev/null +++ b/src/Socialbox/Objects/RpcResponse.php @@ -0,0 +1,65 @@ +id = $id; + $this->result = $result; + } + + /** + * Returns the ID of the response. + * + * @return string The ID of the response. + */ + public function getId(): string + { + return $this->id; + } + + /** + * Returns the result of the response. + * + * @return object|null The result of the response. + */ + public function getResult(): ?object + { + return $this->result; + } + + /** + * Returns an array representation of the object. + * + * @return array The array representation of the object. + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'result' => $this->result->toArray() + ]; + } + + /** + * Returns the response object from an array of data. + * + * @param array $data The data to construct the response from. + * @return RpcResponse The response object. + */ + public static function fromArray(array $data): RpcResponse + { + return new RpcResponse($data['id'], $data['result']); + } +} \ No newline at end of file