N°8834 - Add compatibility with PHP 8.4 (#819)

* N°8834 - Add compatibility with PHP 8.4

* Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
Lenaick
2026-02-26 10:36:32 +01:00
committed by GitHub
parent d4821b7edc
commit fc967c06ce
961 changed files with 12298 additions and 7130 deletions

View File

@@ -220,7 +220,7 @@ class QuestionHelper extends Helper
foreach ($choices as $key => $value) {
$padding = str_repeat(' ', $maxWidth - self::width($key));
$messages[] = sprintf(" [<$tag>%s$padding</$tag>] %s", $key, $value);
$messages[] = \sprintf(" [<$tag>%s$padding</$tag>] %s", $key, $value);
}
return $messages;
@@ -258,11 +258,7 @@ class QuestionHelper extends Helper
$ofs = -1;
$matches = $autocomplete($ret);
$numMatches = \count($matches);
$sttyMode = shell_exec('stty -g');
$isStdin = 'php://stdin' === (stream_get_meta_data($inputStream)['uri'] ?? null);
$r = [$inputStream];
$w = [];
$inputHelper = new TerminalInputHelper($inputStream);
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
shell_exec('stty -icanon -echo');
@@ -272,15 +268,13 @@ class QuestionHelper extends Helper
// Read a keypress
while (!feof($inputStream)) {
while ($isStdin && 0 === @stream_select($r, $w, $w, 0, 100)) {
// Give signal handlers a chance to run
$r = [$inputStream];
}
$inputHelper->waitForInput();
$c = fread($inputStream, 1);
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
shell_exec('stty '.$sttyMode);
// Restore the terminal so it behaves normally again
$inputHelper->finish();
throw new MissingInputException('Aborted.');
} elseif ("\177" === $c) { // Backspace Character
if (0 === $numMatches && 0 !== $i) {
@@ -317,12 +311,12 @@ class QuestionHelper extends Helper
$ofs += ('A' === $c[2]) ? -1 : 1;
$ofs = ($numMatches + $ofs) % $numMatches;
}
} elseif (\ord($c) < 32) {
} elseif ('' === $c || \ord($c) < 32) {
if ("\t" === $c || "\n" === $c) {
if ($numMatches > 0 && -1 !== $ofs) {
$ret = (string) $matches[$ofs];
// Echo out remaining chars for current match
$remainingCharacters = substr($ret, \strlen(trim($this->mostRecentlyEnteredValue($fullChoice))));
$remainingCharacters = substr($ret, \strlen($this->mostRecentlyEnteredValue($fullChoice)));
$output->write($remainingCharacters);
$fullChoice .= $remainingCharacters;
$i = (false === $encoding = mb_detect_encoding($fullChoice, null, true)) ? \strlen($fullChoice) : mb_strlen($fullChoice, $encoding);
@@ -376,14 +370,14 @@ class QuestionHelper extends Helper
if ($numMatches > 0 && -1 !== $ofs) {
$cursor->savePosition();
// Write highlighted text, complete the partially entered response
$charactersEntered = \strlen(trim($this->mostRecentlyEnteredValue($fullChoice)));
$charactersEntered = \strlen($this->mostRecentlyEnteredValue($fullChoice));
$output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $charactersEntered)).'</hl>');
$cursor->restorePosition();
}
}
// Reset stty so it behaves normally again
shell_exec('stty '.$sttyMode);
// Restore the terminal so it behaves normally again
$inputHelper->finish();
return $fullChoice;
}
@@ -434,27 +428,25 @@ class QuestionHelper extends Helper
return $value;
}
$inputHelper = null;
if (self::$stty && Terminal::hasSttyAvailable()) {
$sttyMode = shell_exec('stty -g');
$inputHelper = new TerminalInputHelper($inputStream);
shell_exec('stty -echo');
} elseif ($this->isInteractiveInput($inputStream)) {
throw new RuntimeException('Unable to hide the response.');
}
$value = fgets($inputStream, 4096);
$value = $this->doReadInput($inputStream, helper: $inputHelper);
if (4095 === \strlen($value)) {
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
$errOutput->warning('The value was possibly truncated by your shell or terminal emulator');
}
if (self::$stty && Terminal::hasSttyAvailable()) {
shell_exec('stty '.$sttyMode);
}
// Restore the terminal so it behaves normally again
$inputHelper?->finish();
if (false === $value) {
throw new MissingInputException('Aborted.');
}
if ($trimmable) {
$value = trim($value);
}
@@ -501,19 +493,7 @@ class QuestionHelper extends Helper
return self::$stdinIsInteractive;
}
if (\function_exists('stream_isatty')) {
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
}
if (\function_exists('posix_isatty')) {
return self::$stdinIsInteractive = @posix_isatty(fopen('php://stdin', 'r'));
}
if (!\function_exists('shell_exec')) {
return self::$stdinIsInteractive = true;
}
return self::$stdinIsInteractive = (bool) shell_exec('stty 2> '.('\\' === \DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null'));
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
}
/**
@@ -526,7 +506,7 @@ class QuestionHelper extends Helper
{
if (!$question->isMultiline()) {
$cp = $this->setIOCodepage();
$ret = fgets($inputStream, 4096);
$ret = $this->doReadInput($inputStream);
return $this->resetIOCodepage($cp, $ret);
}
@@ -536,13 +516,11 @@ class QuestionHelper extends Helper
return false;
}
$ret = '';
$cp = $this->setIOCodepage();
while (false !== ($char = fgetc($multiLineStreamReader))) {
if (\PHP_EOL === "{$ret}{$char}") {
break;
}
$ret .= $char;
$ret = $this->doReadInput($multiLineStreamReader, "\x4");
if (stream_get_meta_data($inputStream)['seekable']) {
fseek($inputStream, ftell($multiLineStreamReader));
}
return $this->resetIOCodepage($cp, $ret);
@@ -609,4 +587,35 @@ class QuestionHelper extends Helper
return $cloneStream;
}
/**
* @param resource $inputStream
*/
private function doReadInput($inputStream, ?string $exitChar = null, ?TerminalInputHelper $helper = null): string
{
$ret = '';
$helper ??= new TerminalInputHelper($inputStream, false);
while (!feof($inputStream)) {
$helper->waitForInput();
$char = fread($inputStream, 1);
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
if (false === $char || ('' === $ret && '' === $char)) {
throw new MissingInputException('Aborted.');
}
if (\PHP_EOL === "{$ret}{$char}" || $exitChar === $char) {
break;
}
$ret .= $char;
if (null === $exitChar && "\n" === $char) {
break;
}
}
return $ret;
}
}