updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -20,7 +20,7 @@ use Symfony\Component\Process\Exception\InvalidArgumentException;
*/
abstract class AbstractPipes implements PipesInterface
{
public $pipes = array();
public $pipes = [];
private $inputBuffer = '';
private $input;
@@ -47,17 +47,17 @@ abstract class AbstractPipes implements PipesInterface
public function close()
{
foreach ($this->pipes as $pipe) {
fclose($pipe);
if (\is_resource($pipe)) {
fclose($pipe);
}
}
$this->pipes = array();
$this->pipes = [];
}
/**
* Returns true if a system call has been interrupted.
*
* @return bool
*/
protected function hasSystemCallBeenInterrupted()
protected function hasSystemCallBeenInterrupted(): bool
{
$lastError = $this->lastError;
$this->lastError = null;
@@ -90,10 +90,10 @@ abstract class AbstractPipes implements PipesInterface
*
* @throws InvalidArgumentException When an input iterator yields a non supported value
*/
protected function write()
protected function write(): ?array
{
if (!isset($this->pipes[0])) {
return;
return null;
}
$input = $this->input;
@@ -104,8 +104,8 @@ abstract class AbstractPipes implements PipesInterface
stream_set_blocking($input, 0);
} 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)));
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)));
}
$input = (string) $input;
}
@@ -117,12 +117,12 @@ abstract class AbstractPipes implements PipesInterface
}
}
$r = $e = array();
$w = array($this->pipes[0]);
$r = $e = [];
$w = [$this->pipes[0]];
// let's have a look if something changed in streams
if (false === @stream_select($r, $w, $e, 0, 0)) {
return;
return null;
}
foreach ($w as $stdin) {
@@ -130,12 +130,12 @@ abstract class AbstractPipes implements PipesInterface
$written = fwrite($stdin, $this->inputBuffer);
$this->inputBuffer = substr($this->inputBuffer, $written);
if (isset($this->inputBuffer[0])) {
return array($this->pipes[0]);
return [$this->pipes[0]];
}
}
if ($input) {
for (;;) {
while (true) {
$data = fread($input, self::CHUNK_SIZE);
if (!isset($data[0])) {
break;
@@ -145,7 +145,7 @@ abstract class AbstractPipes implements PipesInterface
if (isset($data[0])) {
$this->inputBuffer = $data;
return array($this->pipes[0]);
return [$this->pipes[0]];
}
}
if (feof($input)) {
@@ -164,14 +164,16 @@ abstract class AbstractPipes implements PipesInterface
fclose($this->pipes[0]);
unset($this->pipes[0]);
} elseif (!$w) {
return array($this->pipes[0]);
return [$this->pipes[0]];
}
return null;
}
/**
* @internal
*/
public function handleError($type, $msg)
public function handleError(int $type, string $msg)
{
$this->lastError = $msg;
}

View File

@@ -20,21 +20,19 @@ namespace Symfony\Component\Process\Pipes;
*/
interface PipesInterface
{
const CHUNK_SIZE = 16384;
public const CHUNK_SIZE = 16384;
/**
* Returns an array of descriptors for the use of proc_open.
*
* @return array
*/
public function getDescriptors();
public function getDescriptors(): array;
/**
* Returns an array of filenames indexed by their related stream in case these pipes use temporary files.
*
* @return string[]
*/
public function getFiles();
public function getFiles(): array;
/**
* Reads data in file handles and pipes.
@@ -44,21 +42,17 @@ interface PipesInterface
*
* @return string[] An array of read data indexed by their fd
*/
public function readAndWrite($blocking, $close = false);
public function readAndWrite(bool $blocking, bool $close = false): array;
/**
* Returns if the current state has open file handles or pipes.
*
* @return bool
*/
public function areOpen();
public function areOpen(): bool;
/**
* Returns if pipes are able to read output.
*
* @return bool
*/
public function haveReadSupport();
public function haveReadSupport(): bool;
/**
* Closes file handles and pipes.

View File

@@ -35,6 +35,19 @@ class UnixPipes extends AbstractPipes
parent::__construct($input);
}
/**
* @return array
*/
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
$this->close();
@@ -43,69 +56,69 @@ class UnixPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function getDescriptors()
public function getDescriptors(): array
{
if (!$this->haveReadSupport) {
$nullstream = fopen('/dev/null', 'c');
return array(
array('pipe', 'r'),
return [
['pipe', 'r'],
$nullstream,
$nullstream,
);
];
}
if ($this->ttyMode) {
return array(
array('file', '/dev/tty', 'r'),
array('file', '/dev/tty', 'w'),
array('file', '/dev/tty', 'w'),
);
return [
['file', '/dev/tty', 'r'],
['file', '/dev/tty', 'w'],
['file', '/dev/tty', 'w'],
];
}
if ($this->ptyMode && Process::isPtySupported()) {
return array(
array('pty'),
array('pty'),
array('pty'),
);
return [
['pty'],
['pty'],
['pty'],
];
}
return array(
array('pipe', 'r'),
array('pipe', 'w'), // stdout
array('pipe', 'w'), // stderr
);
return [
['pipe', 'r'],
['pipe', 'w'], // stdout
['pipe', 'w'], // stderr
];
}
/**
* {@inheritdoc}
*/
public function getFiles()
public function getFiles(): array
{
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function readAndWrite($blocking, $close = false)
public function readAndWrite(bool $blocking, bool $close = false): array
{
$this->unblock();
$w = $this->write();
$read = $e = array();
$read = $e = [];
$r = $this->pipes;
unset($r[0]);
// let's have a look if something changed in streams
set_error_handler(array($this, 'handleError'));
set_error_handler([$this, 'handleError']);
if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
restore_error_handler();
// if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occurred, let's reset pipes
if (!$this->hasSystemCallBeenInterrupted()) {
$this->pipes = array();
$this->pipes = [];
}
return $read;
@@ -118,7 +131,7 @@ class UnixPipes extends AbstractPipes
$read[$type = array_search($pipe, $this->pipes, true)] = '';
do {
$data = fread($pipe, self::CHUNK_SIZE);
$data = @fread($pipe, self::CHUNK_SIZE);
$read[$type] .= $data;
} while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
@@ -138,7 +151,7 @@ class UnixPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function haveReadSupport()
public function haveReadSupport(): bool
{
return $this->haveReadSupport;
}
@@ -146,7 +159,7 @@ class UnixPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function areOpen()
public function areOpen(): bool
{
return (bool) $this->pipes;
}

View File

@@ -17,8 +17,8 @@ use Symfony\Component\Process\Process;
/**
* WindowsPipes implementation uses temporary files as handles.
*
* @see https://bugs.php.net/bug.php?id=51800
* @see https://bugs.php.net/bug.php?id=65650
* @see https://bugs.php.net/51800
* @see https://bugs.php.net/65650
*
* @author Romain Neutron <imprec@gmail.com>
*
@@ -26,13 +26,13 @@ use Symfony\Component\Process\Process;
*/
class WindowsPipes extends AbstractPipes
{
private $files = array();
private $fileHandles = array();
private $lockHandles = array();
private $readBytes = array(
private $files = [];
private $fileHandles = [];
private $lockHandles = [];
private $readBytes = [
Process::STDOUT => 0,
Process::STDERR => 0,
);
];
private $haveReadSupport;
public function __construct($input, bool $haveReadSupport)
@@ -43,11 +43,11 @@ class WindowsPipes extends AbstractPipes
// Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
// Workaround for this problem is to use temporary files instead of pipes on Windows platform.
//
// @see https://bugs.php.net/bug.php?id=51800
$pipes = array(
// @see https://bugs.php.net/51800
$pipes = [
Process::STDOUT => Process::OUT,
Process::STDERR => Process::ERR,
);
];
$tmpDir = sys_get_temp_dir();
$lastError = 'unknown reason';
set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
@@ -56,20 +56,23 @@ class WindowsPipes extends AbstractPipes
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
if (!$h = fopen($file.'.lock', 'w')) {
if (file_exists($file.'.lock')) {
continue 2;
}
restore_error_handler();
throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $lastError));
throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError);
}
if (!flock($h, LOCK_EX | LOCK_NB)) {
if (!flock($h, \LOCK_EX | \LOCK_NB)) {
continue 2;
}
if (isset($this->lockHandles[$pipe])) {
flock($this->lockHandles[$pipe], LOCK_UN);
flock($this->lockHandles[$pipe], \LOCK_UN);
fclose($this->lockHandles[$pipe]);
}
$this->lockHandles[$pipe] = $h;
if (!fclose(fopen($file, 'w')) || !$h = fopen($file, 'r')) {
flock($this->lockHandles[$pipe], LOCK_UN);
if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) {
flock($this->lockHandles[$pipe], \LOCK_UN);
fclose($this->lockHandles[$pipe]);
unset($this->lockHandles[$pipe]);
continue 2;
@@ -85,6 +88,19 @@ class WindowsPipes extends AbstractPipes
parent::__construct($input);
}
/**
* @return array
*/
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
$this->close();
@@ -93,32 +109,32 @@ class WindowsPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function getDescriptors()
public function getDescriptors(): array
{
if (!$this->haveReadSupport) {
$nullstream = fopen('NUL', 'c');
return array(
array('pipe', 'r'),
return [
['pipe', 'r'],
$nullstream,
$nullstream,
);
];
}
// We're not using pipe on Windows platform as it hangs (https://bugs.php.net/bug.php?id=51800)
// We're not using file handles as it can produce corrupted output https://bugs.php.net/bug.php?id=65650
// We're not using pipe on Windows platform as it hangs (https://bugs.php.net/51800)
// We're not using file handles as it can produce corrupted output https://bugs.php.net/65650
// So we redirect output within the commandline and pass the nul device to the process
return array(
array('pipe', 'r'),
array('file', 'NUL', 'w'),
array('file', 'NUL', 'w'),
);
return [
['pipe', 'r'],
['file', 'NUL', 'w'],
['file', 'NUL', 'w'],
];
}
/**
* {@inheritdoc}
*/
public function getFiles()
public function getFiles(): array
{
return $this->files;
}
@@ -126,11 +142,11 @@ class WindowsPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function readAndWrite($blocking, $close = false)
public function readAndWrite(bool $blocking, bool $close = false): array
{
$this->unblock();
$w = $this->write();
$read = $r = $e = array();
$read = $r = $e = [];
if ($blocking) {
if ($w) {
@@ -149,7 +165,7 @@ class WindowsPipes extends AbstractPipes
if ($close) {
ftruncate($fileHandle, 0);
fclose($fileHandle);
flock($this->lockHandles[$type], LOCK_UN);
flock($this->lockHandles[$type], \LOCK_UN);
fclose($this->lockHandles[$type]);
unset($this->fileHandles[$type], $this->lockHandles[$type]);
}
@@ -161,7 +177,7 @@ class WindowsPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function haveReadSupport()
public function haveReadSupport(): bool
{
return $this->haveReadSupport;
}
@@ -169,7 +185,7 @@ class WindowsPipes extends AbstractPipes
/**
* {@inheritdoc}
*/
public function areOpen()
public function areOpen(): bool
{
return $this->pipes && $this->fileHandles;
}
@@ -183,9 +199,9 @@ class WindowsPipes extends AbstractPipes
foreach ($this->fileHandles as $type => $handle) {
ftruncate($handle, 0);
fclose($handle);
flock($this->lockHandles[$type], LOCK_UN);
flock($this->lockHandles[$type], \LOCK_UN);
fclose($this->lockHandles[$type]);
}
$this->fileHandles = $this->lockHandles = array();
$this->fileHandles = $this->lockHandles = [];
}
}