feat: first impl

This commit is contained in:
2025-08-16 21:48:01 +02:00
parent e60ab9d7bc
commit 209c910f33
14 changed files with 444 additions and 0 deletions

49
src/Child.php Normal file
View 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);
}
}