Skip to content

Commit 0b8c101

Browse files
authored
Merge pull request #79 from clue-labs/stream
Forward compatibility with Stream v0.5 and upcoming v0.6
2 parents 26b32eb + 6d19cef commit 0b8c101

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,18 @@ you can use any of its events and methods as usual:
343343

344344
```php
345345
$connection->on('data', function ($chunk) {
346-
echo $data;
346+
echo $chunk;
347347
});
348348

349-
$conenction->on('close', function () {
349+
$connection->on('end', function () {
350+
echo 'ended';
351+
});
352+
353+
$connection->on('error', function (Exception $e) {
354+
echo 'error: ' . $e->getMessage();
355+
});
356+
357+
$connection->on('close', function () {
350358
echo 'closed';
351359
});
352360

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"php": ">=5.3.0",
88
"evenement/evenement": "~2.0|~1.0",
99
"react/event-loop": "0.4.*|0.3.*",
10-
"react/stream": "^0.4.5",
10+
"react/stream": "^0.6 || ^0.5 || ^0.4.5",
1111
"react/promise": "^2.0 || ^1.1"
1212
},
1313
"require-dev": {

src/ConnectionInterface.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,33 @@
2020
* use React's SocketClient component instead.
2121
*
2222
* Because the `ConnectionInterface` implements the underlying
23-
* `DuplexStreamInterface` you can use any of its events and methods as usual.
23+
* `DuplexStreamInterface` you can use any of its events and methods as usual:
24+
*
25+
* ```php
26+
* $connection->on('data', function ($chunk) {
27+
* echo $chunk;
28+
* });
29+
*
30+
* $connection->on('end', function () {
31+
* echo 'ended';
32+
* });
33+
*
34+
* $connection->on('error', function (Exception $e) {
35+
* echo 'error: ' . $e->getMessage();
36+
* });
37+
*
38+
* $connection->on('close', function () {
39+
* echo 'closed';
40+
* });
41+
*
42+
* $connection->write($data);
43+
* $connection->end($data = null);
44+
* $connection->close();
45+
* // …
46+
* ```
47+
*
48+
* For more details, see the
49+
* [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).
2450
*
2551
* @see DuplexStreamInterface
2652
*/

0 commit comments

Comments
 (0)