Skip to content

Commit 34ac555

Browse files
Merge branch '5.0' into 5.1
* 5.0: [Console] Reset question validator attempts only for actual stdin (bis)
2 parents 95242c2 + 8489f8c commit 34ac555

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
@@ -106,7 +106,7 @@ private function doAsk(OutputInterface $output, Question $question)
106106
{
107107
$this->writePrompt($output, $question);
108108

109-
$inputStream = $this->inputStream ?: STDIN;
109+
$inputStream = $this->inputStream ?: fopen('php://stdin', 'r');
110110
$autocomplete = $question->getAutocompleterCallback();
111111

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

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

479479
throw $error;
@@ -506,18 +506,20 @@ private function getShell()
506506
return self::$shell;
507507
}
508508

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

515517
if (\function_exists('stream_isatty')) {
516-
return stream_isatty(fopen('php://input', 'r'));
518+
return stream_isatty($inputStream);
517519
}
518520

519521
if (\function_exists('posix_isatty')) {
520-
return posix_isatty(fopen('php://input', 'r'));
522+
return posix_isatty($inputStream);
521523
}
522524

523525
return true;

0 commit comments

Comments
 (0)