diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 23:39:20 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-05-07 23:39:30 +0300 |
commit | 9a98ac50ff50dda2f2eed1ea825352c50c64440e (patch) | |
tree | cc5c7d36eee1ec934f8728e7f9104a9d2d760856 /src/classes/JobResult.php |
initial
Diffstat (limited to 'src/classes/JobResult.php')
-rw-r--r-- | src/classes/JobResult.php | 96 |
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 |