From c2639092c69695f72753caf7eec90716579a58c6 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 2 Mar 2021 20:31:10 +0300 Subject: create separate classes WorkerClient and MasterClient --- src/Client.php | 42 ------------------------------------------ src/MasterClient.php | 30 ++++++++++++++++++++++++++++++ src/WorkerClient.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 42 deletions(-) create mode 100644 src/MasterClient.php create mode 100644 src/WorkerClient.php diff --git a/src/Client.php b/src/Client.php index 7146f5a..33228d1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -54,48 +54,6 @@ class Client { return $this->recv(); } - /** - * @param array $targets - * @return ResponseMessage - * @throws \Exception - */ - public function poke(array $targets) { - return $this->recv( - $this->sendRequest(new RequestMessage('poke', ['targets' => $targets])) - ); - } - - /** - * @return ResponseMessage - * @throws \Exception - */ - public function status() { - return $this->recv( - $this->sendRequest(new RequestMessage('status')) - ); - } - - /** - * @param array $targets - * @return ResponseMessage - * @throws \Exception - */ - public function poll(array $targets) { - return $this->recv( - $this->sendRequest(new RequestMessage('poll', ['targets' => $targets])) - ); - } - - /** - * @param int $id - * @return ResponseMessage - */ - public function runManual(int $id) { - return $this->recv( - $this->sendRequest(new RequestMessage('run-manual', ['id' => $id])) - ); - } - /** * @param RequestMessage $request * @return int diff --git a/src/MasterClient.php b/src/MasterClient.php new file mode 100644 index 0000000..6a7902b --- /dev/null +++ b/src/MasterClient.php @@ -0,0 +1,30 @@ +recv( + $this->sendRequest(new RequestMessage('poke', ['targets' => $targets])) + ); + } + + /** + * @return ResponseMessage + * @throws \Exception + */ + public function status(): ResponseMessage + { + return $this->recv( + $this->sendRequest(new RequestMessage('status')) + ); + } + +} \ No newline at end of file diff --git a/src/WorkerClient.php b/src/WorkerClient.php new file mode 100644 index 0000000..4e221df --- /dev/null +++ b/src/WorkerClient.php @@ -0,0 +1,42 @@ +recv( + $this->sendRequest(new RequestMessage('status')) + ); + } + + /** + * @param string[] $targets + * @return ResponseMessage + * @throws \Exception + */ + public function poll(array $targets): ResponseMessage + { + return $this->recv( + $this->sendRequest(new RequestMessage('poll', ['targets' => $targets])) + ); + } + + /** + * @param int[] $ids + * @return ResponseMessage + * @throws \Exception + */ + public function runManual(array $ids): ResponseMessage + { + return $this->recv( + $this->sendRequest(new RequestMessage('run-manual', ['ids' => $ids])) + ); + } + +} \ No newline at end of file -- cgit v1.2.3