1 | <?php |
||
44 | class CallResult |
||
45 | { |
||
46 | /** |
||
47 | * The stdout stream |
||
48 | * |
||
49 | * @var resource |
||
50 | */ |
||
51 | protected $stdOut; |
||
52 | |||
53 | /** |
||
54 | * True if there is a stdout |
||
55 | * |
||
56 | * @var boolean |
||
57 | */ |
||
58 | protected $hasStdOut; |
||
59 | |||
60 | /** |
||
61 | * The stderr stream |
||
62 | * |
||
63 | * @var resource |
||
64 | */ |
||
65 | protected $stdErr; |
||
66 | |||
67 | /** |
||
68 | * True if there is a stderr |
||
69 | * |
||
70 | * @var boolean |
||
71 | */ |
||
72 | protected $hasStdErr; |
||
73 | |||
74 | /** |
||
75 | * The return code |
||
76 | * |
||
77 | * @var integer |
||
78 | */ |
||
79 | protected $returnCode; |
||
80 | |||
81 | /** |
||
82 | * Reference to the call that resulted in this result |
||
83 | * |
||
84 | * @var Call |
||
85 | */ |
||
86 | protected $cliCall; |
||
87 | |||
88 | /** |
||
89 | * Creates a new result container for a CLI call |
||
90 | * |
||
91 | * @param Call $cliCall Reference to the call that resulted in this result |
||
92 | * @param resource $stdOut The stdout stream |
||
93 | * @param resource $stdErr The stderr stream |
||
94 | * @param integer $returnCode The return code |
||
95 | */ |
||
96 | 157 | public function __construct(Call $cliCall, $stdOut, $stdErr, $returnCode) |
|
113 | |||
114 | /** |
||
115 | * Destructor closes the result and the internal stream resources |
||
116 | */ |
||
117 | 157 | public function __destruct() |
|
121 | |||
122 | /** |
||
123 | * Returns the reference to the call that resulted in this result |
||
124 | * |
||
125 | * @return Call |
||
126 | */ |
||
127 | 2 | public function getCliCall() |
|
131 | |||
132 | /** |
||
133 | * Returns the stdout stream |
||
134 | * |
||
135 | * @return resource |
||
136 | */ |
||
137 | public function getStdOutStream() |
||
141 | |||
142 | /** |
||
143 | * Returns the contents of stdout |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | 154 | public function getStdOut() |
|
152 | |||
153 | /** |
||
154 | * Returns true if the call resulted in stdout to be populated |
||
155 | * |
||
156 | * @return boolean |
||
157 | */ |
||
158 | 4 | public function hasStdOut() |
|
162 | |||
163 | /** |
||
164 | * Returns the stderr stream |
||
165 | * |
||
166 | * @return resource |
||
167 | */ |
||
168 | public function getStdErrStream() |
||
172 | |||
173 | /** |
||
174 | * Returns the contents of stderr |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | 5 | public function getStdErr() |
|
183 | |||
184 | /** |
||
185 | * Returns true if the call resulted in stderr to be populated |
||
186 | * |
||
187 | * @return boolean |
||
188 | */ |
||
189 | 4 | public function hasStdErr() |
|
193 | |||
194 | /** |
||
195 | * Returns the return code |
||
196 | * |
||
197 | * @return integer |
||
198 | */ |
||
199 | 157 | public function getReturnCode() |
|
203 | |||
204 | /** |
||
205 | * Closes the call result and the internal stream resources |
||
206 | * |
||
207 | * Prevents further usage |
||
208 | */ |
||
209 | 157 | public function close() |
|
210 | { |
||
211 | 157 | if ($this->stdOut !== null) { |
|
212 | 157 | fclose($this->stdOut); |
|
213 | 157 | $this->stdOut = null; |
|
214 | } |
||
215 | 157 | if ($this->stdErr !== null) { |
|
216 | 157 | fclose($this->stdErr); |
|
217 | 157 | $this->stdErr = null; |
|
218 | } |
||
219 | 157 | } |
|
220 | |||
221 | /** |
||
222 | * Checks if the CLI call has succeeded and throws an Exception otherwise |
||
223 | * |
||
224 | * @param string $message The exception message |
||
225 | * @throws CallException If there has been an error when executing |
||
226 | */ |
||
227 | 153 | public function assertSuccess($message) |
|
231 | |||
232 | /** |
||
233 | * Checks if the CLI call has succeeded and throws an Exception otherwise |
||
234 | * |
||
235 | * @param CallResult $result The CLI result |
||
236 | * @param string $message The exception message |
||
237 | * @throws CallException If there has been an error when executing |
||
238 | */ |
||
239 | 153 | public static function throwIfError(CallResult $result, $message) |
|
245 | } |
||
246 | |||
247 |