Files
nih-php-command-builder/src/ExitStatus.php
2026-02-11 22:03:44 +01:00

57 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Nih\CommandBuilder;
/**
* Describes the result of a process after it has terminated.
*
* This class is used to represent the exit status or other termination of a
* child process. Child processes are created via the {@see Command} class and
* their exit status is exposed through the status method, or the wait method of
* a Child process.
*/
final readonly class ExitStatus
{
public function __construct(
private ?int $code,
private ?int $signal = null,
private ?int $stoppedSignal = null,
) {
}
/**
* Was termination successful? Signal termination is not considered a
* success, and success is defined as a zero exit status.
*/
public function success(): bool
{
return $this->code === 0;
}
/**
* The exit code of the process, if any.
*/
public function code(): ?int
{
return $this->code > -1 ? $this->code : null;
}
/**
* If the process was terminated by a signal, returns that signal.
*/
public function signal(): ?int
{
return $this->signal;
}
/**
* If the process was stopped by a signal, returns that signal.
*/
public function stoppedSignal(): ?int
{
return $this->stoppedSignal;
}
}