Skip to content

Commit

Permalink
[Console] block input stream if needed When the input stream used in …
Browse files Browse the repository at this point in the history
…the question helper is not blocking, the default value is always used as the stream return false. In order to fix that, we force the stream to be in blocking state and go back to the old state after so other logic is not impacted by this change
  • Loading branch information
joelwurtz committed May 25, 2023
1 parent a349882 commit 47ec02a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,18 @@ private function doAsk(OutputInterface $output, Question $question)
}

if (false === $ret) {
$isBlocked = stream_get_meta_data($inputStream)['blocked'] ?? true;

if (!$isBlocked) {
stream_set_blocking($inputStream, true);
}

$ret = $this->readInput($inputStream, $question);

if (!$isBlocked) {
stream_set_blocking($inputStream, false);
}

if (false === $ret) {
throw new MissingInputException('Aborted.');
}
Expand Down

0 comments on commit 47ec02a

Please sign in to comment.