summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/protocol-jsonrpc/src/Response.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
commita1ec78bf0dc93d0e05e5f066f1949dc3baecea06 (patch)
treeee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/protocol-jsonrpc/src/Response.php
parentInitial commit. (diff)
downloadicingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.tar.xz
icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.zip
Adding upstream version 0.20.0.upstream/0.20.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/protocol-jsonrpc/src/Response.php')
-rw-r--r--vendor/gipfl/protocol-jsonrpc/src/Response.php128
1 files changed, 128 insertions, 0 deletions
diff --git a/vendor/gipfl/protocol-jsonrpc/src/Response.php b/vendor/gipfl/protocol-jsonrpc/src/Response.php
new file mode 100644
index 0000000..3a5ad90
--- /dev/null
+++ b/vendor/gipfl/protocol-jsonrpc/src/Response.php
@@ -0,0 +1,128 @@
+<?php
+
+namespace gipfl\Protocol\JsonRpc;
+
+class Response extends Packet
+{
+ /** @var mixed|null This could be null when sending a parse error */
+ protected $id;
+
+ /** @var mixed */
+ protected $result;
+
+ /** @var Error|null */
+ protected $error;
+
+ /** @var string */
+ protected $message;
+
+ public function __construct($id = null)
+ {
+ $this->id = $id;
+ }
+
+ /**
+ * @param Request $request
+ * @return Response
+ */
+ public static function forRequest(Request $request)
+ {
+ return new Response($request->getId());
+ }
+
+ /**
+ * @return object
+ */
+ #[\ReturnTypeWillChange]
+ public function jsonSerialize()
+ {
+ $plain = [
+ 'jsonrpc' => '2.0',
+ ];
+ if ($this->hasExtraProperties()) {
+ $plain += (array) $this->getExtraProperties();
+ }
+
+ if ($this->id !== null) {
+ $plain['id'] = $this->id;
+ }
+
+ if ($this->error === null) {
+ $plain['result'] = $this->result;
+ } else {
+ if (! isset($plain['id'])) {
+ $plain['id'] = null;
+ }
+ $plain['error'] = $this->error;
+ }
+
+ return (object) $plain;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getResult()
+ {
+ return $this->result;
+ }
+
+ /**
+ * @param $result
+ * @return $this
+ */
+ public function setResult($result)
+ {
+ $this->result = $result;
+
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasId()
+ {
+ return null !== $this->id;
+ }
+
+ /**
+ * @return null|int|string
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @param $id
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
+ public function isError()
+ {
+ return $this->error !== null;
+ }
+
+ /**
+ * @return Error|null
+ */
+ public function getError()
+ {
+ return $this->error;
+ }
+
+ /**
+ * @param $error
+ * @return $this;
+ */
+ public function setError(Error $error)
+ {
+ $this->error = $error;
+
+ return $this;
+ }
+}