Skip to content

Commit

Permalink
Detect EOF when reading input stream
Browse files Browse the repository at this point in the history
[Console] Change back to fgets() in DialogHelper
  • Loading branch information
lenar committed Jul 27, 2011
1 parent 8700cd6 commit 07298ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Symfony/Component/Console/Helper/DialogHelper.php
Expand Up @@ -20,7 +20,7 @@
*/
class DialogHelper extends Helper
{
private $inputStream;
private $inputStream = STDIN;

This comment has been minimized.

Copy link
@michelsalib

michelsalib Jul 31, 2011

Since this commit, I get Notice: Use of undefined constant STDIN - assumed 'STDIN' everytime I try to use the console.

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jul 31, 2011

Member

Can you try this in your shell?

$ php -r 'var_dump(STDIN);'

It should output resource(1) of type (stream). If not, please try php -r 'var_dump(PHP_SAPI);'. If it's not CLI, then maybe your setup is a bit weird and you are running the CGI version in your CLI?

This comment has been minimized.

Copy link
@michelsalib

michelsalib Jul 31, 2011

I am indeed running the CGI version in my CLI (of this I am sure). Is there any solution for that ?

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jul 31, 2011

Member

Well, I suppose this part of the patch (the move from ternary operator to setting STDIN as default) should be reverted. If there is no alternative inputStream specified though, it will keep failing. Can you check if that's the case and submit a PR if this fixes your problem?

This comment has been minimized.

Copy link
@michelsalib

michelsalib Jul 31, 2011

You mean I shall reverting the whole patch, test, and if it work submit PR ?

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jul 31, 2011

Member

Well, I think you need to revert the change at line 23, and then at line 38 needs to be like this:

 $ret = fgets($this->inputStream ?: STDIN, 4096);

That way if inputstream is configured (let's hope so), you shouldn't see the notice.

This comment has been minimized.

Copy link
@michelsalib

michelsalib Jul 31, 2011

It works! I am preparing a PR :)

This comment has been minimized.

Copy link
@Seldaek

Seldaek Jul 31, 2011

Member

Great, thanks


/**
* Asks a question to the user.
Expand All @@ -35,7 +35,8 @@ public function ask(OutputInterface $output, $question, $default = null)
{
$output->write($question);

if (false === $ret = stream_get_line(null === $this->inputStream ? STDIN : $this->inputStream, 4096, "\n")) {
$ret = fgets($this->inputStream, 4096);
if (false === $ret) {
throw new \RuntimeException('Aborted');
}
$ret = trim($ret);
Expand Down

0 comments on commit 07298ac

Please sign in to comment.