Skip to content

Commit 8489f8c

Browse files
Merge branch '4.4' into 5.0
* 4.4: [Console] Reset question validator attempts only for actual stdin (bis)
2 parents d981566 + a3660e1 commit 8489f8c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Helper/QuestionHelper.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function doAsk(OutputInterface $output, Question $question)
104104
{
105105
$this->writePrompt($output, $question);
106106

107-
$inputStream = $this->inputStream ?: STDIN;
107+
$inputStream = $this->inputStream ?: fopen('php://stdin', 'r');
108108
$autocomplete = $question->getAutocompleterCallback();
109109

110110
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
@@ -472,7 +472,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
472472
} catch (\Exception $error) {
473473
}
474474

475-
$attempts = $attempts ?? -(int) $this->isTty();
475+
$attempts = $attempts ?? -(int) $this->askForever();
476476
}
477477

478478
throw $error;
@@ -505,18 +505,20 @@ private function getShell()
505505
return self::$shell;
506506
}
507507

508-
private function isTty(): bool
508+
private function askForever(): bool
509509
{
510-
if (!\defined('STDIN')) {
510+
$inputStream = $this->inputStream ?: fopen('php://stdin', 'r');
511+
512+
if ('php://stdin' !== (stream_get_meta_data($inputStream)['url'] ?? null)) {
511513
return true;
512514
}
513515

514516
if (\function_exists('stream_isatty')) {
515-
return stream_isatty(fopen('php://input', 'r'));
517+
return stream_isatty($inputStream);
516518
}
517519

518520
if (\function_exists('posix_isatty')) {
519-
return posix_isatty(fopen('php://input', 'r'));
521+
return posix_isatty($inputStream);
520522
}
521523

522524
return true;

0 commit comments

Comments
 (0)