Skip to content

Commit

Permalink
Forward compatibility with Stream v0.5 and upcoming v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Mar 9, 2017
1 parent 26b32eb commit 6d19cef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,18 @@ you can use any of its events and methods as usual:

```php
$connection->on('data', function ($chunk) {
echo $data;
echo $chunk;
});

$conenction->on('close', function () {
$connection->on('end', function () {
echo 'ended';
});

$connection->on('error', function (Exception $e) {
echo 'error: ' . $e->getMessage();
});

$connection->on('close', function () {
echo 'closed';
});

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=5.3.0",
"evenement/evenement": "~2.0|~1.0",
"react/event-loop": "0.4.*|0.3.*",
"react/stream": "^0.4.5",
"react/stream": "^0.6 || ^0.5 || ^0.4.5",
"react/promise": "^2.0 || ^1.1"
},
"require-dev": {
Expand Down
28 changes: 27 additions & 1 deletion src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,33 @@
* use React's SocketClient component instead.
*
* Because the `ConnectionInterface` implements the underlying
* `DuplexStreamInterface` you can use any of its events and methods as usual.
* `DuplexStreamInterface` you can use any of its events and methods as usual:
*
* ```php
* $connection->on('data', function ($chunk) {
* echo $chunk;
* });
*
* $connection->on('end', function () {
* echo 'ended';
* });
*
* $connection->on('error', function (Exception $e) {
* echo 'error: ' . $e->getMessage();
* });
*
* $connection->on('close', function () {
* echo 'closed';
* });
*
* $connection->write($data);
* $connection->end($data = null);
* $connection->close();
* // …
* ```
*
* For more details, see the
* [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface).
*
* @see DuplexStreamInterface
*/
Expand Down

0 comments on commit 6d19cef

Please sign in to comment.