package and depencies
This commit is contained in:
162
vendor/symfony/process/Process.php
vendored
162
vendor/symfony/process/Process.php
vendored
@@ -140,7 +140,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws LogicException When proc_open is not installed
|
||||
*/
|
||||
public function __construct(array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
|
||||
public function __construct(array $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60)
|
||||
{
|
||||
if (!\function_exists('proc_open')) {
|
||||
throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.');
|
||||
@@ -185,11 +185,9 @@ class Process implements \IteratorAggregate
|
||||
* @param mixed $input The input as stream resource, scalar or \Traversable, or null for no input
|
||||
* @param int|float|null $timeout The timeout in seconds or null to disable
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @throws LogicException When proc_open is not installed
|
||||
*/
|
||||
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
|
||||
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60): static
|
||||
{
|
||||
$process = new static([], $cwd, $env, $input, $timeout);
|
||||
$process->commandline = $command;
|
||||
@@ -197,10 +195,7 @@ class Process implements \IteratorAggregate
|
||||
return $process;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
public function __sleep(): array
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
|
||||
}
|
||||
@@ -266,7 +261,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function mustRun(callable $callback = null, array $env = []): self
|
||||
public function mustRun(callable $callback = null, array $env = []): static
|
||||
{
|
||||
if (0 !== $this->run($callback, $env)) {
|
||||
throw new ProcessFailedException($this);
|
||||
@@ -313,7 +308,7 @@ class Process implements \IteratorAggregate
|
||||
$env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv(), $env, 'strcasecmp') : $this->getDefaultEnv();
|
||||
|
||||
if (\is_array($commandline = $this->commandline)) {
|
||||
$commandline = implode(' ', array_map([$this, 'escapeArgument'], $commandline));
|
||||
$commandline = implode(' ', array_map($this->escapeArgument(...), $commandline));
|
||||
|
||||
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
||||
// exec is mandatory to deal with sending a signal to the process
|
||||
@@ -376,8 +371,6 @@ class Process implements \IteratorAggregate
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process is already running
|
||||
*
|
||||
@@ -385,7 +378,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function restart(callable $callback = null, array $env = []): self
|
||||
public function restart(callable $callback = null, array $env = []): static
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Process is already running.');
|
||||
@@ -412,7 +405,7 @@ class Process implements \IteratorAggregate
|
||||
* @throws ProcessSignaledException When process stopped after receiving signal
|
||||
* @throws LogicException When process is not yet started
|
||||
*/
|
||||
public function wait(callable $callback = null)
|
||||
public function wait(callable $callback = null): int
|
||||
{
|
||||
$this->requireProcessIsStarted(__FUNCTION__);
|
||||
|
||||
@@ -495,7 +488,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return int|null The process id if running, null otherwise
|
||||
*/
|
||||
public function getPid()
|
||||
public function getPid(): ?int
|
||||
{
|
||||
return $this->isRunning() ? $this->processInformation['pid'] : null;
|
||||
}
|
||||
@@ -511,7 +504,7 @@ class Process implements \IteratorAggregate
|
||||
* @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
|
||||
* @throws RuntimeException In case of failure
|
||||
*/
|
||||
public function signal(int $signal)
|
||||
public function signal(int $signal): static
|
||||
{
|
||||
$this->doSignal($signal, true);
|
||||
|
||||
@@ -526,7 +519,7 @@ class Process implements \IteratorAggregate
|
||||
* @throws RuntimeException In case the process is already running
|
||||
* @throws LogicException if an idle timeout is set
|
||||
*/
|
||||
public function disableOutput()
|
||||
public function disableOutput(): static
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Disabling output while the process is running is not possible.');
|
||||
@@ -547,7 +540,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws RuntimeException In case the process is already running
|
||||
*/
|
||||
public function enableOutput()
|
||||
public function enableOutput(): static
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Enabling output while the process is running is not possible.');
|
||||
@@ -560,10 +553,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Returns true in case the output is disabled, false otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isOutputDisabled()
|
||||
public function isOutputDisabled(): bool
|
||||
{
|
||||
return $this->outputDisabled;
|
||||
}
|
||||
@@ -571,12 +562,10 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Returns the current output of the process (STDOUT).
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*/
|
||||
public function getOutput()
|
||||
public function getOutput(): string
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__);
|
||||
|
||||
@@ -593,12 +582,10 @@ class Process implements \IteratorAggregate
|
||||
* In comparison with the getOutput method which always return the whole
|
||||
* output, this one returns the new output since the last call.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*/
|
||||
public function getIncrementalOutput()
|
||||
public function getIncrementalOutput(): string
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__);
|
||||
|
||||
@@ -619,11 +606,8 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*
|
||||
* @return \Generator<string, string>
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator(int $flags = 0)
|
||||
public function getIterator(int $flags = 0): \Generator
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__, false);
|
||||
|
||||
@@ -675,7 +659,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function clearOutput()
|
||||
public function clearOutput(): static
|
||||
{
|
||||
ftruncate($this->stdout, 0);
|
||||
fseek($this->stdout, 0);
|
||||
@@ -687,12 +671,10 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Returns the current error output of the process (STDERR).
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*/
|
||||
public function getErrorOutput()
|
||||
public function getErrorOutput(): string
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__);
|
||||
|
||||
@@ -710,12 +692,10 @@ class Process implements \IteratorAggregate
|
||||
* whole error output, this one returns the new error output since the last
|
||||
* call.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*/
|
||||
public function getIncrementalErrorOutput()
|
||||
public function getIncrementalErrorOutput(): string
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__);
|
||||
|
||||
@@ -734,7 +714,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function clearErrorOutput()
|
||||
public function clearErrorOutput(): static
|
||||
{
|
||||
ftruncate($this->stderr, 0);
|
||||
fseek($this->stderr, 0);
|
||||
@@ -748,7 +728,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return int|null The exit status code, null if the Process is not terminated
|
||||
*/
|
||||
public function getExitCode()
|
||||
public function getExitCode(): ?int
|
||||
{
|
||||
$this->updateStatus(false);
|
||||
|
||||
@@ -766,7 +746,7 @@ class Process implements \IteratorAggregate
|
||||
* @see http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
* @see http://en.wikipedia.org/wiki/Unix_signal
|
||||
*/
|
||||
public function getExitCodeText()
|
||||
public function getExitCodeText(): ?string
|
||||
{
|
||||
if (null === $exitcode = $this->getExitCode()) {
|
||||
return null;
|
||||
@@ -777,10 +757,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Checks if the process ended successfully.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful()
|
||||
public function isSuccessful(): bool
|
||||
{
|
||||
return 0 === $this->getExitCode();
|
||||
}
|
||||
@@ -790,11 +768,9 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* It always returns false on Windows.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws LogicException In case the process is not terminated
|
||||
*/
|
||||
public function hasBeenSignaled()
|
||||
public function hasBeenSignaled(): bool
|
||||
{
|
||||
$this->requireProcessIsTerminated(__FUNCTION__);
|
||||
|
||||
@@ -806,12 +782,10 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* It is only meaningful if hasBeenSignaled() returns true.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws RuntimeException In case --enable-sigchild is activated
|
||||
* @throws LogicException In case the process is not terminated
|
||||
*/
|
||||
public function getTermSignal()
|
||||
public function getTermSignal(): int
|
||||
{
|
||||
$this->requireProcessIsTerminated(__FUNCTION__);
|
||||
|
||||
@@ -827,11 +801,9 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* It always returns false on Windows.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws LogicException In case the process is not terminated
|
||||
*/
|
||||
public function hasBeenStopped()
|
||||
public function hasBeenStopped(): bool
|
||||
{
|
||||
$this->requireProcessIsTerminated(__FUNCTION__);
|
||||
|
||||
@@ -843,11 +815,9 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* It is only meaningful if hasBeenStopped() returns true.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws LogicException In case the process is not terminated
|
||||
*/
|
||||
public function getStopSignal()
|
||||
public function getStopSignal(): int
|
||||
{
|
||||
$this->requireProcessIsTerminated(__FUNCTION__);
|
||||
|
||||
@@ -856,10 +826,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Checks if the process is currently running.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRunning()
|
||||
public function isRunning(): bool
|
||||
{
|
||||
if (self::STATUS_STARTED !== $this->status) {
|
||||
return false;
|
||||
@@ -872,20 +840,16 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Checks if the process has been started with no regard to the current state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarted()
|
||||
public function isStarted(): bool
|
||||
{
|
||||
return self::STATUS_READY != $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the process is terminated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isTerminated()
|
||||
public function isTerminated(): bool
|
||||
{
|
||||
$this->updateStatus(false);
|
||||
|
||||
@@ -896,10 +860,8 @@ class Process implements \IteratorAggregate
|
||||
* Gets the process status.
|
||||
*
|
||||
* The status is one of: ready, started, terminated.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
public function getStatus(): string
|
||||
{
|
||||
$this->updateStatus(false);
|
||||
|
||||
@@ -914,7 +876,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return int|null The exit-code of the process or null if it's not running
|
||||
*/
|
||||
public function stop(float $timeout = 10, int $signal = null)
|
||||
public function stop(float $timeout = 10, int $signal = null): ?int
|
||||
{
|
||||
$timeoutMicro = microtime(true) + $timeout;
|
||||
if ($this->isRunning()) {
|
||||
@@ -981,30 +943,24 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Gets the command line to be executed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommandLine()
|
||||
public function getCommandLine(): string
|
||||
{
|
||||
return \is_array($this->commandline) ? implode(' ', array_map([$this, 'escapeArgument'], $this->commandline)) : $this->commandline;
|
||||
return \is_array($this->commandline) ? implode(' ', array_map($this->escapeArgument(...), $this->commandline)) : $this->commandline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the process timeout in seconds (max. runtime).
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function getTimeout()
|
||||
public function getTimeout(): ?float
|
||||
{
|
||||
return $this->timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the process idle timeout in seconds (max. time since last output).
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function getIdleTimeout()
|
||||
public function getIdleTimeout(): ?float
|
||||
{
|
||||
return $this->idleTimeout;
|
||||
}
|
||||
@@ -1018,7 +974,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws InvalidArgumentException if the timeout is negative
|
||||
*/
|
||||
public function setTimeout(?float $timeout)
|
||||
public function setTimeout(?float $timeout): static
|
||||
{
|
||||
$this->timeout = $this->validateTimeout($timeout);
|
||||
|
||||
@@ -1035,7 +991,7 @@ class Process implements \IteratorAggregate
|
||||
* @throws LogicException if the output is disabled
|
||||
* @throws InvalidArgumentException if the timeout is negative
|
||||
*/
|
||||
public function setIdleTimeout(?float $timeout)
|
||||
public function setIdleTimeout(?float $timeout): static
|
||||
{
|
||||
if (null !== $timeout && $this->outputDisabled) {
|
||||
throw new LogicException('Idle timeout cannot be set while the output is disabled.');
|
||||
@@ -1053,7 +1009,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws RuntimeException In case the TTY mode is not supported
|
||||
*/
|
||||
public function setTty(bool $tty)
|
||||
public function setTty(bool $tty): static
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR && $tty) {
|
||||
throw new RuntimeException('TTY mode is not supported on Windows platform.');
|
||||
@@ -1070,10 +1026,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Checks if the TTY mode is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isTty()
|
||||
public function isTty(): bool
|
||||
{
|
||||
return $this->tty;
|
||||
}
|
||||
@@ -1083,7 +1037,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPty(bool $bool)
|
||||
public function setPty(bool $bool): static
|
||||
{
|
||||
$this->pty = $bool;
|
||||
|
||||
@@ -1092,20 +1046,16 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Returns PTY state.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPty()
|
||||
public function isPty(): bool
|
||||
{
|
||||
return $this->pty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the working directory.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWorkingDirectory()
|
||||
public function getWorkingDirectory(): ?string
|
||||
{
|
||||
if (null === $this->cwd) {
|
||||
// getcwd() will return false if any one of the parent directories does not have
|
||||
@@ -1121,7 +1071,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setWorkingDirectory(string $cwd)
|
||||
public function setWorkingDirectory(string $cwd): static
|
||||
{
|
||||
$this->cwd = $cwd;
|
||||
|
||||
@@ -1130,10 +1080,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Gets the environment variables.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEnv()
|
||||
public function getEnv(): array
|
||||
{
|
||||
return $this->env;
|
||||
}
|
||||
@@ -1145,7 +1093,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEnv(array $env)
|
||||
public function setEnv(array $env): static
|
||||
{
|
||||
$this->env = $env;
|
||||
|
||||
@@ -1173,7 +1121,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws LogicException In case the process is running
|
||||
*/
|
||||
public function setInput($input)
|
||||
public function setInput(mixed $input): static
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new LogicException('Input cannot be set while the process is running.');
|
||||
@@ -1256,19 +1204,13 @@ class Process implements \IteratorAggregate
|
||||
{
|
||||
static $isTtySupported;
|
||||
|
||||
if (null === $isTtySupported) {
|
||||
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
|
||||
}
|
||||
|
||||
return $isTtySupported;
|
||||
return $isTtySupported ??= ('/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PTY is supported on the current operating system.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPtySupported()
|
||||
public static function isPtySupported(): bool
|
||||
{
|
||||
static $result;
|
||||
|
||||
@@ -1307,10 +1249,8 @@ class Process implements \IteratorAggregate
|
||||
* the user callback (if present) with the received output.
|
||||
*
|
||||
* @param callable|null $callback The user defined PHP callback
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function buildCallback(callable $callback = null)
|
||||
protected function buildCallback(callable $callback = null): \Closure
|
||||
{
|
||||
if ($this->outputDisabled) {
|
||||
return function ($type, $data) use ($callback): bool {
|
||||
@@ -1358,10 +1298,8 @@ class Process implements \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSigchildEnabled()
|
||||
protected function isSigchildEnabled(): bool
|
||||
{
|
||||
if (null !== self::$sigchild) {
|
||||
return self::$sigchild;
|
||||
|
Reference in New Issue
Block a user