@@ -51,6 +51,9 @@ class Process implements \IteratorAggregate
51
51
public const ITER_SKIP_OUT = 4 ; // Use this flag to skip STDOUT while iterating
52
52
public const ITER_SKIP_ERR = 8 ; // Use this flag to skip STDERR while iterating
53
53
54
+ /**
55
+ * @var (\Closure('out'|'err', string):bool)|null
56
+ */
54
57
private ?\Closure $ callback = null ;
55
58
private array |string $ commandline ;
56
59
private ?string $ cwd ;
@@ -231,7 +234,7 @@ public function __clone()
231
234
* The STDOUT and STDERR are also available after the process is finished
232
235
* via the getOutput() and getErrorOutput() methods.
233
236
*
234
- * @param callable|null $callback A PHP callback to run whenever there is some
237
+ * @param ( callable('out'|'err', string):bool) |null $callback A PHP callback to run whenever there is some
235
238
* output available on STDOUT or STDERR
236
239
*
237
240
* @return int The exit status code
@@ -257,6 +260,8 @@ public function run(?callable $callback = null, array $env = []): int
257
260
* This is identical to run() except that an exception is thrown if the process
258
261
* exits with a non-zero exit code.
259
262
*
263
+ * @param (callable('out'|'err', string):bool)|null $callback
264
+ *
260
265
* @return $this
261
266
*
262
267
* @throws ProcessFailedException if the process didn't terminate successfully
@@ -284,7 +289,7 @@ public function mustRun(?callable $callback = null, array $env = []): static
284
289
* the output in real-time while writing the standard input to the process.
285
290
* It allows to have feedback from the independent process during execution.
286
291
*
287
- * @param callable|null $callback A PHP callback to run whenever there is some
292
+ * @param ( callable('out'|'err', string):bool) |null $callback A PHP callback to run whenever there is some
288
293
* output available on STDOUT or STDERR
289
294
*
290
295
* @throws ProcessStartFailedException When process can't be launched
@@ -395,7 +400,7 @@ public function start(?callable $callback = null, array $env = []): void
395
400
*
396
401
* Be warned that the process is cloned before being started.
397
402
*
398
- * @param callable|null $callback A PHP callback to run whenever there is some
403
+ * @param ( callable('out'|'err', string):bool) |null $callback A PHP callback to run whenever there is some
399
404
* output available on STDOUT or STDERR
400
405
*
401
406
* @throws ProcessStartFailedException When process can't be launched
@@ -424,7 +429,7 @@ public function restart(?callable $callback = null, array $env = []): static
424
429
* from the output in real-time while writing the standard input to the process.
425
430
* It allows to have feedback from the independent process during execution.
426
431
*
427
- * @param callable|null $callback A valid PHP callback
432
+ * @param ( callable('out'|'err', string):bool) |null $callback A valid PHP callback
428
433
*
429
434
* @return int The exitcode of the process
430
435
*
@@ -471,6 +476,8 @@ public function wait(?callable $callback = null): int
471
476
* from the output in real-time while writing the standard input to the process.
472
477
* It allows to have feedback from the independent process during execution.
473
478
*
479
+ * @param callable('out'|'err', string):bool $callback
480
+ *
474
481
* @throws RuntimeException When process timed out
475
482
* @throws LogicException When process is not yet started
476
483
* @throws ProcessTimedOutException In case the timeout was reached
@@ -1291,7 +1298,8 @@ private function getDescriptors(bool $hasCallback): array
1291
1298
* The callbacks adds all occurred output to the specific buffer and calls
1292
1299
* the user callback (if present) with the received output.
1293
1300
*
1294
- * @param callable|null $callback The user defined PHP callback
1301
+ * @param (callable('out'|'err', string):bool)|null $callback The user defined PHP callback
1302
+ * @return \Closure('out'|'err', string):bool
1295
1303
*/
1296
1304
protected function buildCallback (?callable $ callback = null ): \Closure
1297
1305
{
@@ -1301,15 +1309,19 @@ protected function buildCallback(?callable $callback = null): \Closure
1301
1309
1302
1310
$ out = self ::OUT ;
1303
1311
1304
- return function ($ type , $ data ) use ($ callback , $ out ): bool {
1305
- if ($ out == $ type ) {
1306
- $ this ->addOutput ($ data );
1307
- } else {
1308
- $ this ->addErrorOutput ($ data );
1309
- }
1312
+ return
1313
+ /**
1314
+ * @param 'out'|'err' $type
1315
+ */
1316
+ function (string $ type , string $ data ) use ($ callback , $ out ): bool {
1317
+ if ($ out == $ type ) {
1318
+ $ this ->addOutput ($ data );
1319
+ } else {
1320
+ $ this ->addErrorOutput ($ data );
1321
+ }
1310
1322
1311
- return null !== $ callback && $ callback ($ type , $ data );
1312
- };
1323
+ return null !== $ callback && $ callback ($ type , $ data );
1324
+ };
1313
1325
}
1314
1326
1315
1327
/**
0 commit comments