Skip to content

Commit

Permalink
Merge branch 'QA'
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Aug 27, 2020
2 parents c97fd75 + e0da85e commit 29ce64e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Fix lexer to not allow numbers with letters (#300)
* Add support for INVISIBLE keyword (#292)
* Fix the "$" might be a character used in a name (#301)
* Fix use stream_select instead of non-blocking STDIN (#309)

## [5.3.1] - 2020-03-20

Expand Down
19 changes: 14 additions & 5 deletions src/Utils/CLI.php
Expand Up @@ -16,7 +16,7 @@
use function in_array;
use function rtrim;
use function stream_get_contents;
use function stream_set_blocking;
use function stream_select;
use function var_export;
use const STDIN;

Expand Down Expand Up @@ -260,10 +260,19 @@ public function runTokenize()

public function readStdin()
{
stream_set_blocking(STDIN, false);
$stdin = stream_get_contents(STDIN);
// restore-default block-mode setting
stream_set_blocking(STDIN, true);
$read = [STDIN];
$write = [];
$except = [];

// Assume there's nothing to be read from STDIN.
$stdin = null;

// Try to read from STDIN. Wait 0.2 second before timing out.
$result = stream_select($read, $write, $except, 0, 2000);

if ($result > 0) {
$stdin = stream_get_contents(STDIN);
}

return $stdin;
}
Expand Down

0 comments on commit 29ce64e

Please sign in to comment.