Skip to content

Commit

Permalink
bug #37286 [Console] Reset question validator attempts only for actua…
Browse files Browse the repository at this point in the history
…l stdin (bis) (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Console] Reset question validator attempts only for actual stdin (bis)

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

#37160 [fails](https://travis-ci.org/github/symfony/symfony/jobs/698492147), this should fix it by looking at the actual input stream.

Commits
-------

867642e [Console] Reset question validator attempts only for actual stdin (bis)
  • Loading branch information
nicolas-grekas committed Jun 15, 2020
2 parents 52612b1 + 867642e commit 943c630
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 943c630

Please sign in to comment.