-
Notifications
You must be signed in to change notification settings - Fork 4
/
CommandResult.php
71 lines (60 loc) · 1.51 KB
/
CommandResult.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Enqueue\AsyncCommand;
final class CommandResult implements \JsonSerializable
{
/**
* @var int
*/
private $exitCode;
/**
* @var string
*/
private $output;
/**
* @var string
*/
private $errorOutput;
/**
* @param int $exitCode
* @param string $output
* @param string $errorOutput
*/
public function __construct(int $exitCode, string $output, string $errorOutput)
{
$this->exitCode = $exitCode;
$this->output = $output;
$this->errorOutput = $errorOutput;
}
public function getExitCode(): int
{
return $this->exitCode;
}
public function getOutput(): string
{
return $this->output;
}
public function getErrorOutput(): string
{
return $this->errorOutput;
}
public function jsonSerialize(): array
{
return [
'exitCode' => $this->exitCode,
'output' => $this->output,
'errorOutput' => $this->errorOutput,
];
}
public static function jsonUnserialize(string $json): self
{
$data = json_decode($json, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf(
'The malformed json given. Error %s and message %s',
json_last_error(),
json_last_error_msg()
));
}
return new self($data['exitCode'], $data['output'], $data['errorOutput']);
}
}