Skip to content

Commit b6cf7f3

Browse files
committed
The Stdin is now internal to the Readline
1 parent a7a2b8f commit b6cf7f3

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/Readline.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Clue\React\Stdio;
44

55
use Evenement\EventEmitter;
6+
use React\Stream\ReadableStreamInterface;
7+
use React\Stream\WritableStreamInterface;
68

79
class Readline extends EventEmitter
810
{
@@ -34,8 +36,11 @@ class Readline extends EventEmitter
3436
private $output;
3537
private $sequencer;
3638

37-
public function __construct($output)
39+
public function __construct(ReadableStreamInterface $input, WritableStreamInterface $output)
3840
{
41+
// input data emits a single char into readline
42+
$input->on('data', array($this, 'onChar'));
43+
3944
$this->output = $output;
4045

4146
$this->sequencer = new Sequencer();

src/Stdio.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ public function __construct(LoopInterface $loop, $input = true)
2222

2323
$this->output = new Stdout(STDOUT);
2424

25-
$this->readline = $readline = new Readline($this->output);
25+
$this->readline = new Readline($this->input, $this->output);
2626

2727
$that = $this;
2828

29-
// input data emits a single char into readline
30-
$this->input->on('data', function ($data) use ($that, $readline) {
29+
// stdin emits single chars
30+
$this->input->on('data', function ($data) use ($that) {
3131
$that->emit('char', array($data, $that));
32-
$readline->onChar($data);
3332
});
3433

3534
// readline data emits a new line
36-
$readline->on('data', function($line) use ($that) {
35+
$this->readline->on('data', function($line) use ($that) {
3736
$that->emit('line', array($line, $that));
3837
});
3938

tests/ReadlineTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ class ReadlineTest extends TestCase
66
{
77
public function setUp()
88
{
9+
$this->input = $this->getMock('React\Stream\ReadableStreamInterface');
910
$this->output = $this->getMockBuilder('Clue\React\Stdio\Stdout')->disableOriginalConstructor()->getMock();
10-
$this->readline = new Readline($this->output);
11+
$this->readline = new Readline($this->input, $this->output);
1112
}
1213

1314
public function testSettersReturnSelf()

tests/StdioTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use React\EventLoop\Factory;
4+
use Clue\React\Stdio\Stdio;
5+
6+
class StdioTest extends TestCase
7+
{
8+
private $loop;
9+
10+
public function setUp()
11+
{
12+
$this->loop = Factory::create();
13+
}
14+
15+
public function testCtor()
16+
{
17+
$stdio = new Stdio($this->loop);
18+
}
19+
}

0 commit comments

Comments
 (0)