summaryrefslogtreecommitdiff
path: root/src/messages/ResponseMessage.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/messages/ResponseMessage.php')
-rw-r--r--src/messages/ResponseMessage.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/messages/ResponseMessage.php b/src/messages/ResponseMessage.php
new file mode 100644
index 0000000..5101ed4
--- /dev/null
+++ b/src/messages/ResponseMessage.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace jobd\messages;
+
+class ResponseMessage extends Message {
+
+ protected $requestNo;
+ protected $error;
+ protected $data;
+
+ /**
+ * Response constructor.
+ *
+ * @param int $request_no
+ * @param null $error
+ * @param null $data
+ */
+ public function __construct(int $request_no, $error = null, $data = null)
+ {
+ parent::__construct(Message::RESPONSE);
+
+ $this->requestNo = $request_no;
+ $this->error = $error;
+ $this->data = $data;
+ }
+
+ /**
+ * @return array
+ */
+ protected function getContent(): array
+ {
+ $response = [
+ 'no' => $this->requestNo
+ ];
+
+ if (!is_null($this->error))
+ $response['error'] = $this->error;
+
+ if (!is_null(!$this->data))
+ $response['data'] = $this->data;
+
+ return $response;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getError()
+ {
+ return $this->error;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getData()
+ {
+ return $this->data;
+ }
+
+ /**
+ * @return int
+ */
+ public function getRequestNo(): int
+ {
+ return $this->requestNo;
+ }
+
+} \ No newline at end of file