Skip to content

Commit 2972666

Browse files
committed
Move forwardEvents helper method to Util, add tests
1 parent 39c6986 commit 2972666

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

CompositeStream.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function __construct(ReadableStreamInterface $readable, WritableStreamInt
1515
$this->readable = $readable;
1616
$this->writable = $writable;
1717

18-
$this->forwardEvents($this->readable, array('data', 'end', 'error', 'close'));
19-
$this->forwardEvents($this->writable, array('drain', 'error', 'close', 'pipe'));
18+
Util::forwardEvents($this->readable, $this, array('data', 'end', 'error', 'close'));
19+
Util::forwardEvents($this->writable, $this, array('drain', 'error', 'close', 'pipe'));
2020

2121
$this->readable->on('close', array($this, 'close'));
2222
$this->writable->on('close', array($this, 'close'));
@@ -81,15 +81,4 @@ public function close()
8181
$this->readable->close();
8282
$this->writable->close();
8383
}
84-
85-
protected function forwardEvents($stream, array $events)
86-
{
87-
$that = $this;
88-
89-
foreach ($events as $event) {
90-
$stream->on($event, function () use ($event, $that) {
91-
$that->emit($event, func_get_args());
92-
});
93-
}
94-
}
95-
}
84+
}

Util.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,13 @@ public static function pipe(ReadableStreamInterface $source, WritableStreamInter
3333
});
3434
}
3535
}
36+
37+
public static function forwardEvents($source, $target, array $events)
38+
{
39+
foreach ($events as $event) {
40+
$source->on($event, function () use ($event, $target) {
41+
$target->emit($event, func_get_args());
42+
});
43+
}
44+
}
3645
}

0 commit comments

Comments
 (0)