upgraded dependencies
This commit is contained in:
180
vendor/symfony/process/Process.php
vendored
180
vendor/symfony/process/Process.php
vendored
@@ -27,6 +27,8 @@ use Symfony\Component\Process\Pipes\WindowsPipes;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Romain Neutron <imprec@gmail.com>
|
||||
*
|
||||
* @implements \IteratorAggregate<string, string>
|
||||
*/
|
||||
class Process implements \IteratorAggregate
|
||||
{
|
||||
@@ -71,6 +73,7 @@ class Process implements \IteratorAggregate
|
||||
private $incrementalErrorOutputOffset = 0;
|
||||
private $tty = false;
|
||||
private $pty;
|
||||
private $options = ['suppress_errors' => true, 'bypass_shell' => true];
|
||||
|
||||
private $useFileHandles = false;
|
||||
/** @var PipesInterface */
|
||||
@@ -137,16 +140,12 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws LogicException When proc_open is not installed
|
||||
*/
|
||||
public function __construct($command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
|
||||
public function __construct(array $command, string $cwd = null, array $env = null, $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.');
|
||||
}
|
||||
|
||||
if (!\is_array($command)) {
|
||||
@trigger_error(sprintf('Passing a command as string when creating a "%s" instance is deprecated since Symfony 4.2, pass it as an array of its arguments instead, or use the "Process::fromShellCommandline()" constructor if you need features provided by the shell.', __CLASS__), \E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->commandline = $command;
|
||||
$this->cwd = $cwd;
|
||||
|
||||
@@ -213,7 +212,11 @@ class Process implements \IteratorAggregate
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->stop(0);
|
||||
if ($this->options['create_new_console'] ?? false) {
|
||||
$this->processPipes->close();
|
||||
} else {
|
||||
$this->stop(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
@@ -320,10 +323,7 @@ class Process implements \IteratorAggregate
|
||||
$commandline = $this->replacePlaceholders($commandline, $env);
|
||||
}
|
||||
|
||||
$options = ['suppress_errors' => true];
|
||||
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$options['bypass_shell'] = true;
|
||||
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
|
||||
} elseif (!$this->useFileHandles && $this->isSigchildEnabled()) {
|
||||
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
|
||||
@@ -349,7 +349,7 @@ class Process implements \IteratorAggregate
|
||||
throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.', $this->cwd));
|
||||
}
|
||||
|
||||
$this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $options);
|
||||
$this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
|
||||
|
||||
if (!\is_resource($this->process)) {
|
||||
throw new RuntimeException('Unable to launch a new process.');
|
||||
@@ -511,7 +511,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($signal)
|
||||
public function signal(int $signal)
|
||||
{
|
||||
$this->doSignal($signal, true);
|
||||
|
||||
@@ -532,7 +532,7 @@ class Process implements \IteratorAggregate
|
||||
throw new RuntimeException('Disabling output while the process is running is not possible.');
|
||||
}
|
||||
if (null !== $this->idleTimeout) {
|
||||
throw new LogicException('Output can not be disabled while an idle timeout is set.');
|
||||
throw new LogicException('Output cannot be disabled while an idle timeout is set.');
|
||||
}
|
||||
|
||||
$this->outputDisabled = true;
|
||||
@@ -571,7 +571,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Returns the current output of the process (STDOUT).
|
||||
*
|
||||
* @return string The process output
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
@@ -593,7 +593,7 @@ 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 The process 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
|
||||
@@ -620,10 +620,10 @@ class Process implements \IteratorAggregate
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
*
|
||||
* @return \Generator
|
||||
* @return \Generator<string, string>
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator($flags = 0)
|
||||
public function getIterator(int $flags = 0)
|
||||
{
|
||||
$this->readPipesForOutput(__FUNCTION__, false);
|
||||
|
||||
@@ -687,7 +687,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Returns the current error output of the process (STDERR).
|
||||
*
|
||||
* @return string The process error output
|
||||
* @return string
|
||||
*
|
||||
* @throws LogicException in case the output has been disabled
|
||||
* @throws LogicException In case the process is not started
|
||||
@@ -710,7 +710,7 @@ class Process implements \IteratorAggregate
|
||||
* whole error output, this one returns the new error output since the last
|
||||
* call.
|
||||
*
|
||||
* @return string The process 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
|
||||
@@ -778,7 +778,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Checks if the process ended successfully.
|
||||
*
|
||||
* @return bool true if the process ended successfully, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful()
|
||||
{
|
||||
@@ -816,7 +816,7 @@ class Process implements \IteratorAggregate
|
||||
$this->requireProcessIsTerminated(__FUNCTION__);
|
||||
|
||||
if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) {
|
||||
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
|
||||
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal cannot be retrieved.');
|
||||
}
|
||||
|
||||
return $this->processInformation['termsig'];
|
||||
@@ -857,7 +857,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Checks if the process is currently running.
|
||||
*
|
||||
* @return bool true if the process is currently running, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isRunning()
|
||||
{
|
||||
@@ -873,7 +873,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Checks if the process has been started with no regard to the current state.
|
||||
*
|
||||
* @return bool true if status is ready, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
@@ -883,7 +883,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Checks if the process is terminated.
|
||||
*
|
||||
* @return bool true if process is terminated, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isTerminated()
|
||||
{
|
||||
@@ -897,7 +897,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* The status is one of: ready, started, terminated.
|
||||
*
|
||||
* @return string The current process status
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
@@ -914,7 +914,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @return int|null The exit-code of the process or null if it's not running
|
||||
*/
|
||||
public function stop($timeout = 10, $signal = null)
|
||||
public function stop(float $timeout = 10, int $signal = null)
|
||||
{
|
||||
$timeoutMicro = microtime(true) + $timeout;
|
||||
if ($this->isRunning()) {
|
||||
@@ -982,7 +982,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Gets the command line to be executed.
|
||||
*
|
||||
* @return string The command to execute
|
||||
* @return string
|
||||
*/
|
||||
public function getCommandLine()
|
||||
{
|
||||
@@ -990,27 +990,9 @@ class Process implements \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command line to be executed.
|
||||
* Gets the process timeout in seconds (max. runtime).
|
||||
*
|
||||
* @param string|array $commandline The command to execute
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated since Symfony 4.2.
|
||||
*/
|
||||
public function setCommandLine($commandline)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), \E_USER_DEPRECATED);
|
||||
|
||||
$this->commandline = $commandline;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the process timeout (max. runtime).
|
||||
*
|
||||
* @return float|null The timeout in seconds or null if it's disabled
|
||||
* @return float|null
|
||||
*/
|
||||
public function getTimeout()
|
||||
{
|
||||
@@ -1018,9 +1000,9 @@ class Process implements \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the process idle timeout (max. time since last output).
|
||||
* Gets the process idle timeout in seconds (max. time since last output).
|
||||
*
|
||||
* @return float|null The timeout in seconds or null if it's disabled
|
||||
* @return float|null
|
||||
*/
|
||||
public function getIdleTimeout()
|
||||
{
|
||||
@@ -1032,13 +1014,11 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* To disable the timeout, set this value to null.
|
||||
*
|
||||
* @param int|float|null $timeout The timeout in seconds
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws InvalidArgumentException if the timeout is negative
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
public function setTimeout(?float $timeout)
|
||||
{
|
||||
$this->timeout = $this->validateTimeout($timeout);
|
||||
|
||||
@@ -1046,21 +1026,19 @@ class Process implements \IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the process idle timeout (max. time since last output).
|
||||
* Sets the process idle timeout (max. time since last output) in seconds.
|
||||
*
|
||||
* To disable the timeout, set this value to null.
|
||||
*
|
||||
* @param int|float|null $timeout The timeout in seconds
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException if the output is disabled
|
||||
* @throws InvalidArgumentException if the timeout is negative
|
||||
*/
|
||||
public function setIdleTimeout($timeout)
|
||||
public function setIdleTimeout(?float $timeout)
|
||||
{
|
||||
if (null !== $timeout && $this->outputDisabled) {
|
||||
throw new LogicException('Idle timeout can not be set while the output is disabled.');
|
||||
throw new LogicException('Idle timeout cannot be set while the output is disabled.');
|
||||
}
|
||||
|
||||
$this->idleTimeout = $this->validateTimeout($timeout);
|
||||
@@ -1071,13 +1049,11 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Enables or disables the TTY mode.
|
||||
*
|
||||
* @param bool $tty True to enabled and false to disable
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException In case the TTY mode is not supported
|
||||
*/
|
||||
public function setTty($tty)
|
||||
public function setTty(bool $tty)
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR && $tty) {
|
||||
throw new RuntimeException('TTY mode is not supported on Windows platform.');
|
||||
@@ -1087,7 +1063,7 @@ class Process implements \IteratorAggregate
|
||||
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
|
||||
}
|
||||
|
||||
$this->tty = (bool) $tty;
|
||||
$this->tty = $tty;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1095,7 +1071,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Checks if the TTY mode is enabled.
|
||||
*
|
||||
* @return bool true if the TTY mode is enabled, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isTty()
|
||||
{
|
||||
@@ -1105,13 +1081,11 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Sets PTY mode.
|
||||
*
|
||||
* @param bool $bool
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPty($bool)
|
||||
public function setPty(bool $bool)
|
||||
{
|
||||
$this->pty = (bool) $bool;
|
||||
$this->pty = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1129,7 +1103,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Gets the working directory.
|
||||
*
|
||||
* @return string|null The current working directory or null on failure
|
||||
* @return string|null
|
||||
*/
|
||||
public function getWorkingDirectory()
|
||||
{
|
||||
@@ -1145,11 +1119,9 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Sets the current working directory.
|
||||
*
|
||||
* @param string $cwd The new working directory
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setWorkingDirectory($cwd)
|
||||
public function setWorkingDirectory(string $cwd)
|
||||
{
|
||||
$this->cwd = $cwd;
|
||||
|
||||
@@ -1159,7 +1131,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Gets the environment variables.
|
||||
*
|
||||
* @return array The current environment variables
|
||||
* @return array
|
||||
*/
|
||||
public function getEnv()
|
||||
{
|
||||
@@ -1183,7 +1155,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Gets the Process input.
|
||||
*
|
||||
* @return resource|string|\Iterator|null The Process input
|
||||
* @return resource|string|\Iterator|null
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
@@ -1204,7 +1176,7 @@ class Process implements \IteratorAggregate
|
||||
public function setInput($input)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new LogicException('Input can not be set while the process is running.');
|
||||
throw new LogicException('Input cannot be set while the process is running.');
|
||||
}
|
||||
|
||||
$this->input = ProcessUtils::validateInput(__METHOD__, $input);
|
||||
@@ -1212,26 +1184,6 @@ class Process implements \IteratorAggregate
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether environment variables will be inherited or not.
|
||||
*
|
||||
* @param bool $inheritEnv
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated since Symfony 4.4, env variables are always inherited
|
||||
*/
|
||||
public function inheritEnvironmentVariables($inheritEnv = true)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, env variables are always inherited.', __METHOD__), \E_USER_DEPRECATED);
|
||||
|
||||
if (!$inheritEnv) {
|
||||
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a check between the timeout definition and the time the process started.
|
||||
*
|
||||
@@ -1259,6 +1211,44 @@ class Process implements \IteratorAggregate
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LogicException in case process is not started
|
||||
*/
|
||||
public function getStartTime(): float
|
||||
{
|
||||
if (!$this->isStarted()) {
|
||||
throw new LogicException('Start time is only available after process start.');
|
||||
}
|
||||
|
||||
return $this->starttime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines options to pass to the underlying proc_open().
|
||||
*
|
||||
* @see https://php.net/proc_open for the options supported by PHP.
|
||||
*
|
||||
* Enabling the "create_new_console" option allows a subprocess to continue
|
||||
* to run after the main process exited, on both Windows and *nix
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Setting options while the process is running is not possible.');
|
||||
}
|
||||
|
||||
$defaultOptions = $this->options;
|
||||
$existingOptions = ['blocking_pipes', 'create_process_group', 'create_new_console'];
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (!\in_array($key, $existingOptions)) {
|
||||
$this->options = $defaultOptions;
|
||||
throw new LogicException(sprintf('Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode('", "', $existingOptions)));
|
||||
}
|
||||
$this->options[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether TTY is supported on the current operating system.
|
||||
*/
|
||||
@@ -1318,7 +1308,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback The user defined PHP callback
|
||||
*
|
||||
* @return \Closure A PHP closure
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function buildCallback(callable $callback = null)
|
||||
{
|
||||
@@ -1346,7 +1336,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param bool $blocking Whether to use a blocking read call
|
||||
*/
|
||||
protected function updateStatus($blocking)
|
||||
protected function updateStatus(bool $blocking)
|
||||
{
|
||||
if (self::STATUS_STARTED !== $this->status) {
|
||||
return;
|
||||
@@ -1509,7 +1499,7 @@ class Process implements \IteratorAggregate
|
||||
{
|
||||
if (null === $pid = $this->getPid()) {
|
||||
if ($throwException) {
|
||||
throw new LogicException('Can not send signal on a non running process.');
|
||||
throw new LogicException('Cannot send signal on a non running process.');
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user