upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -1,6 +1,26 @@
CHANGELOG
=========
5.2.0
-----
* added `Process::setOptions()` to set `Process` specific options
* added option `create_new_console` to allow a subprocess to continue
to run after the main script exited, both on Linux and on Windows
5.1.0
-----
* added `Process::getStartTime()` to retrieve the start time of the process as float
5.0.0
-----
* removed `Process::inheritEnvironmentVariables()`
* removed `PhpProcess::setPhpBinary()`
* `Process` must be instantiated with a command array, use `Process::fromShellCommandline()` when the command should be parsed by the shell
* removed `Process::setCommandLine()`
4.4.0
-----

View File

@@ -31,10 +31,8 @@ class ExecutableFinder
/**
* Adds new possible suffix to check for executable.
*
* @param string $suffix
*/
public function addSuffix($suffix)
public function addSuffix(string $suffix)
{
$this->suffixes[] = $suffix;
}
@@ -46,9 +44,9 @@ class ExecutableFinder
* @param string|null $default The default to return if no executable is found
* @param array $extraDirs Additional dirs to check into
*
* @return string|null The executable path or default value
* @return string|null
*/
public function find($name, $default = null, array $extraDirs = [])
public function find(string $name, string $default = null, array $extraDirs = [])
{
if (\ini_get('open_basedir')) {
$searchPath = array_merge(explode(\PATH_SEPARATOR, \ini_get('open_basedir')), $extraDirs);

View File

@@ -17,6 +17,8 @@ use Symfony\Component\Process\Exception\RuntimeException;
* Provides a way to continuously write to the input of a Process until the InputStream is closed.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @implements \IteratorAggregate<int, string>
*/
class InputStream implements \IteratorAggregate
{
@@ -67,7 +69,7 @@ class InputStream implements \IteratorAggregate
}
/**
* @return \Traversable
* @return \Traversable<int, string>
*/
#[\ReturnTypeWillChange]
public function getIterator()

View File

@@ -29,11 +29,9 @@ class PhpExecutableFinder
/**
* Finds The PHP executable.
*
* @param bool $includeArgs Whether or not include command arguments
*
* @return string|false The PHP executable path or false if it cannot be found
* @return string|false
*/
public function find($includeArgs = true)
public function find(bool $includeArgs = true)
{
if ($php = getenv('PHP_BINARY')) {
if (!is_executable($php)) {
@@ -91,7 +89,7 @@ class PhpExecutableFinder
/**
* Finds the PHP executable arguments.
*
* @return array The PHP executable arguments
* @return array
*/
public function findArguments()
{

View File

@@ -58,18 +58,6 @@ class PhpProcess extends Process
throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
}
/**
* Sets the path to the PHP binary to use.
*
* @deprecated since Symfony 4.2, use the $php argument of the constructor instead.
*/
public function setPhpBinary($php)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the $php argument of the constructor instead.', __METHOD__), \E_USER_DEPRECATED);
$this->setCommandLine($php);
}
/**
* {@inheritdoc}
*/

View File

@@ -105,7 +105,7 @@ abstract class AbstractPipes implements PipesInterface
} elseif (!isset($this->inputBuffer[0])) {
if (!\is_string($input)) {
if (!\is_scalar($input)) {
throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class($this->input), \gettype($input)));
throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', get_debug_type($this->input), get_debug_type($input)));
}
$input = (string) $input;
}

View File

@@ -35,10 +35,7 @@ class UnixPipes extends AbstractPipes
parent::__construct($input);
}
/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

View File

@@ -88,10 +88,7 @@ class WindowsPipes extends AbstractPipes
parent::__construct($input);
}
/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}

View File

@@ -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;

View File

@@ -35,11 +35,11 @@ class ProcessUtils
* @param string $caller The name of method call that validates the input
* @param mixed $input The input to validate
*
* @return mixed The validated input
* @return mixed
*
* @throws InvalidArgumentException In case the input is not valid
*/
public static function validateInput($caller, $input)
public static function validateInput(string $caller, $input)
{
if (null !== $input) {
if (\is_resource($input)) {

View File

@@ -3,6 +3,17 @@ Process Component
The Process component executes commands in sub-processes.
Sponsor
-------
The Process component for Symfony 5.4/6.0 is [backed][1] by [SensioLabs][2].
As the creator of Symfony, SensioLabs supports companies using Symfony, with an
offering encompassing consultancy, expertise, services, training, and technical
assistance to ensure the success of web application development projects.
Help Symfony by [sponsoring][3] its development!
Resources
---------
@@ -11,3 +22,7 @@ Resources
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)
[1]: https://symfony.com/backers
[2]: https://sensiolabs.com
[3]: https://symfony.com/sponsor

View File

@@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.1.3",
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16"
},
"autoload": {