From a3660e1c74be6d5a02b884f57e80a4e440a705ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 15 Jun 2020 14:27:36 +0200 Subject: [PATCH] [Console] Reset question validator attempts only for actual stdin (bis) --- Helper/QuestionHelper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index f9d74ebe5..1b60786c9 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -104,7 +104,7 @@ private function doAsk(OutputInterface $output, Question $question) { $this->writePrompt($output, $question); - $inputStream = $this->inputStream ?: STDIN; + $inputStream = $this->inputStream ?: fopen('php://stdin', 'r'); $autocomplete = $question->getAutocompleterCallback(); if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) { @@ -474,7 +474,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output } catch (\Exception $error) { } - $attempts = $attempts ?? -(int) $this->isTty(); + $attempts = $attempts ?? -(int) $this->askForever(); } throw $error; @@ -507,18 +507,20 @@ private function getShell() return self::$shell; } - private function isTty(): bool + private function askForever(): bool { - if (!\defined('STDIN')) { + $inputStream = $this->inputStream ?: fopen('php://stdin', 'r'); + + if ('php://stdin' !== (stream_get_meta_data($inputStream)['url'] ?? null)) { return true; } if (\function_exists('stream_isatty')) { - return stream_isatty(fopen('php://input', 'r')); + return stream_isatty($inputStream); } if (\function_exists('posix_isatty')) { - return posix_isatty(fopen('php://input', 'r')); + return posix_isatty($inputStream); } return true;