summaryrefslogtreecommitdiff
path: root/src/classes/JobResult.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/JobResult.php')
-rw-r--r--src/classes/JobResult.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/classes/JobResult.php b/src/classes/JobResult.php
new file mode 100644
index 0000000..c42b6b0
--- /dev/null
+++ b/src/classes/JobResult.php
@@ -0,0 +1,96 @@
+<?php
+
+class JobResult {
+
+ /**
+ * @var string $result
+ */
+ protected $result;
+
+ /**
+ * @var int $returnCode
+ */
+ protected $returnCode;
+
+ /**
+ * @var string|null $signal
+ */
+ protected $signal;
+
+ /**
+ * @var string $stdout
+ */
+ protected $stdout;
+
+ /**
+ * @var string $stderr
+ */
+ protected $stderr;
+
+ /**
+ * @param string $result
+ * @param int $return_code
+ * @param string $stdout
+ * @param string $stderr
+ * @param null $signal
+ * @return $this
+ */
+ public function setResult(string $result,
+ int $return_code,
+ string $stdout,
+ string $stderr,
+ $signal = null): JobResult
+ {
+ $this->result = $result;
+ $this->returnCode = $return_code;
+ $this->stdout = $stdout;
+ $this->stderr = $stderr;
+ $this->signal = $signal;
+
+ return $this;
+ }
+
+ /**
+ * @param string $error
+ * @return $this
+ */
+ public function setError(string $error): JobResult
+ {
+ $this->result = Job::RESULT_FAIL;
+ $this->stderr = $error;
+
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isFailed(): bool
+ {
+ return $this->result == Job::RESULT_FAIL;
+ }
+
+ /**
+ * @return string
+ */
+ public function getStdout(): string
+ {
+ return $this->stdout;
+ }
+
+ /**
+ * @return mixed|null
+ */
+ public function getStdoutAsJSON() {
+ $json = jsonDecode($this->stdout);
+ return $json ? $json : null;
+ }
+
+ /**
+ * @return string
+ */
+ public function getError(): string {
+ return $this->stderr ?? '';
+ }
+
+} \ No newline at end of file