1 | <?php |
||
9 | class Process extends BaseEvent |
||
10 | { |
||
11 | /** |
||
12 | * The command to run. |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $command; |
||
16 | |||
17 | /** |
||
18 | * The working directory. |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $cwd; |
||
22 | |||
23 | /** |
||
24 | * The user the command should run as. |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $user; |
||
28 | |||
29 | /** |
||
30 | * Indicates if the command should not overlap itself. |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $mutuallyExclusive = false; |
||
34 | |||
35 | /** |
||
36 | * Indicates if the command should run in background. |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $runInBackground = true; |
||
40 | |||
41 | /** |
||
42 | * The location that output should be sent to. |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $output = '/dev/null'; |
||
46 | |||
47 | /** |
||
48 | * The location of error output |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $errorOutput = '/dev/null'; |
||
52 | |||
53 | /** |
||
54 | * Indicates whether output should be appended or added (> vs >>) |
||
55 | * @var bool |
||
56 | */ |
||
57 | protected $shouldAppendOutput = true; |
||
58 | |||
59 | 5 | public function __construct(/* string */ $command) |
|
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | public function getCommand() |
||
73 | |||
74 | /** |
||
75 | * @return string |
||
76 | */ |
||
77 | public function __toString() |
||
81 | |||
82 | /** |
||
83 | * Build the command string. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 5 | public function compileCommand() |
|
116 | |||
117 | /** |
||
118 | * Run the given event. |
||
119 | * |
||
120 | * @return OsProcess |
||
121 | */ |
||
122 | public function run() |
||
140 | |||
141 | /** |
||
142 | * Run the command in the foreground. |
||
143 | * |
||
144 | * @return OsProcess |
||
145 | */ |
||
146 | protected function runCommandInForeground() |
||
153 | |||
154 | /** |
||
155 | * Run the command in the background. |
||
156 | * |
||
157 | * @return OsProcess |
||
158 | */ |
||
159 | protected function runCommandInBackground() |
||
166 | |||
167 | /** |
||
168 | * Get the mutex path for managing concurrency |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | protected function getMutexPath() |
||
176 | |||
177 | /** |
||
178 | * Do not allow the event to overlap each other. |
||
179 | * |
||
180 | * @return $this |
||
181 | */ |
||
182 | public function preventOverlapping() |
||
193 | |||
194 | /** |
||
195 | * Tells you whether this event has been denied from mutual exclusiveness |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | protected function isLocked() |
||
203 | |||
204 | /** |
||
205 | * State that the command should run in the foreground |
||
206 | * |
||
207 | * @return $this |
||
208 | */ |
||
209 | public function runInForeground() |
||
215 | |||
216 | /** |
||
217 | * State that the command should run in the background. |
||
218 | * |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function runInBackground() |
||
227 | |||
228 | /** |
||
229 | * Set which user the command should run as. |
||
230 | * |
||
231 | * @param string? $user |
||
232 | * @return $this |
||
233 | */ |
||
234 | 1 | public function asUser(/* string? */ $user) |
|
242 | |||
243 | /** |
||
244 | * Change the current working directory. |
||
245 | * |
||
246 | * @param string $directory |
||
247 | * @return $this |
||
248 | */ |
||
249 | 1 | public function in(/* string */ $directory) |
|
257 | |||
258 | /** |
||
259 | * Whether we append or redirect output |
||
260 | * |
||
261 | * @param bool $switch |
||
262 | * @return $this |
||
263 | */ |
||
264 | 2 | public function appendOutput(/* boolean */ $switch = true) |
|
272 | |||
273 | /** |
||
274 | * Set the file or location where to send file descriptor 1 to |
||
275 | * |
||
276 | * @param string $output |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function outputTo(/* string */ $output) |
||
287 | |||
288 | /** |
||
289 | * Set the file or location where to send file descriptor 2 to |
||
290 | * |
||
291 | * @param string $output |
||
292 | * @return $this |
||
293 | */ |
||
294 | public function errorOutputTo(/* string */ $output) |
||
302 | } |
||
303 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.