From 66a3b4028339fa82a94ac8804ea965f45c720f17 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 3 Sep 2024 11:39:41 -0400 Subject: [PATCH] Add RpcRequest class to handle RPC request data --- src/Socialbox/Objects/RpcRequest.php | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/Socialbox/Objects/RpcRequest.php diff --git a/src/Socialbox/Objects/RpcRequest.php b/src/Socialbox/Objects/RpcRequest.php new file mode 100644 index 0000000..eca5d2a --- /dev/null +++ b/src/Socialbox/Objects/RpcRequest.php @@ -0,0 +1,80 @@ +id = $data['id'] ?? null; + $this->method = $data['method']; + $this->parameters = $data['parameters'] ?? null; + } + + /** + * Returns the ID of the request. + * + * @return string|null The ID of the request. + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * Returns the method of the request. + * + * @return string The method of the request. + */ + public function getMethod(): string + { + return $this->method; + } + + /** + * Returns the parameters of the request. + * + * @return array|null The parameters of the request. + */ + public function getParameters(): ?array + { + return $this->parameters; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'method' => $this->method, + 'parameters' => $this->parameters + ]; + } + + /** + * Returns the request object from an array of data. + * + * @param array $data The data to construct the object from. + * @return RpcRequest The request object. + */ + public static function fromArray(array $data): RpcRequest + { + return static($data); + } +} \ No newline at end of file