feat: first impl
This commit is contained in:
49
src/Child.php
Normal file
49
src/Child.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Nih\CommandBuilder;
|
||||
|
||||
final class Child
|
||||
{
|
||||
/**
|
||||
* @param resource $proc The process handle.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly ?ChildStdin $stdin,
|
||||
public readonly ?ChildStdout $stdout,
|
||||
public readonly ?ChildStderr $stderr,
|
||||
public $proc,
|
||||
) {
|
||||
}
|
||||
|
||||
public function id(): int
|
||||
{
|
||||
$status = proc_get_status($this->proc);
|
||||
return $status['pid'];
|
||||
}
|
||||
|
||||
public function output(): Output
|
||||
{
|
||||
$stdout = $this->stdout?->getContents();
|
||||
$stderr = $this->stderr?->getContents();
|
||||
$code = proc_close($this->proc);
|
||||
|
||||
return new Output($stdout, $stderr, $code);
|
||||
}
|
||||
|
||||
public function status(): int
|
||||
{
|
||||
return proc_close($this->proc);
|
||||
}
|
||||
|
||||
public function wait(): void
|
||||
{
|
||||
proc_close($this->proc);
|
||||
}
|
||||
|
||||
public function kill(): bool
|
||||
{
|
||||
return proc_terminate($this->proc, 10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user