| 1 |
<?php |
| 2 |
|
| 3 |
namespace Shellbox\Command; |
| 4 |
|
| 5 |
class UnboxedResult { |
| 6 |
/** @var int|null */ |
| 7 |
private $exitCode; |
| 8 |
|
| 9 |
/** @var string|null */ |
| 10 |
private $stdout; |
| 11 |
|
| 12 |
/** @var string|null */ |
| 13 |
private $stderr; |
| 14 |
|
| 15 |
/** |
| 16 |
* Set the exit code |
| 17 |
* |
| 18 |
* @param int $exitCode |
| 19 |
* @return $this |
| 20 |
*/ |
| 21 |
public function exitCode( $exitCode ) { |
| 22 |
$this->exitCode = $exitCode; |
| 23 |
return $this; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Set the stdout contents |
| 28 |
* |
| 29 |
* @param string $stdout |
| 30 |
* @return $this |
| 31 |
*/ |
| 32 |
public function stdout( $stdout ) { |
| 33 |
$this->stdout = $stdout; |
| 34 |
return $this; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Set the stderr contents |
| 39 |
* |
| 40 |
* @param string $stderr |
| 41 |
* @return $this |
| 42 |
*/ |
| 43 |
public function stderr( $stderr ) { |
| 44 |
$this->stderr = $stderr; |
| 45 |
return $this; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Combine another result with this one. The semantics are like the shell's |
| 50 |
* "&&" operator, although in practice we use this to upgrade an |
| 51 |
* UnboxedResult to a BoxedResult, so $this is typically empty. |
| 52 |
* |
| 53 |
* @param UnboxedResult $other |
| 54 |
*/ |
| 55 |
public function merge( UnboxedResult $other ) { |
| 56 |
if ( !$this->exitCode ) { |
| 57 |
$this->exitCode = $other->exitCode; |
| 58 |
} |
| 59 |
$this->stdout .= $other->getStdout(); |
| 60 |
$this->stderr .= $other->getStderr(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Returns exit code of the process |
| 65 |
* |
| 66 |
* @return int|null |
| 67 |
*/ |
| 68 |
public function getExitCode() { |
| 69 |
return $this->exitCode; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Returns stdout of the process |
| 74 |
* |
| 75 |
* @return string|null |
| 76 |
*/ |
| 77 |
public function getStdout() { |
| 78 |
return $this->stdout; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns stderr of the process or null if the Command was configured to add stderr to stdout |
| 83 |
* with includeStderr( true ) |
| 84 |
* |
| 85 |
* @return string|null |
| 86 |
*/ |
| 87 |
public function getStderr() { |
| 88 |
return $this->stderr; |
| 89 |
} |
| 90 |
} |