Skip to content

Commit a3660e1

Browse files
[Console] Reset question validator attempts only for actual stdin (bis)
1 parent be9cb92 commit a3660e1

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()) {
@@ -474,7 +474,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
474474
} catch (\Exception $error) {
475475
}
476476

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

480480
throw $error;
@@ -507,18 +507,20 @@ private function getShell()
507507
return self::$shell;
508508
}
509509

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

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

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

524526
return true;

0 commit comments

Comments
 (0)