From 697fdd9b2a5642fdd93fe14ee81d03a332a5e801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 30 Mar 2017 01:09:49 +0200 Subject: [PATCH] Update examples to use Stream v0.6 API --- README.md | 10 ---------- composer.json | 3 ++- examples/03-netcat.php | 11 +++++------ examples/04-web.php | 5 ++--- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bfd0cc3..d8b6b30 100644 --- a/README.md +++ b/README.md @@ -501,16 +501,6 @@ $promise->cancel(); Calling `cancel()` on a pending promise will cancel the underlying DNS lookup and/or the underlying TCP/IP connection and reject the resulting promise. -The legacy `Connector` class can be used for backwards-compatiblity reasons. -It works very much like the newer `DnsConnector` but instead has to be -set up like this: - -```php -$connector = new React\SocketClient\Connector($loop, $dns); - -$connector->connect('www.google.com:80')->then($callback); -``` - > Advanced usage: Internally, the `DnsConnector` relies on a `Resolver` to look up the IP address for the given hostname. It will then replace the hostname in the destination URI with this IP and diff --git a/composer.json b/composer.json index 6e6eeb2..b271f4b 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "require-dev": { "clue/block-react": "^1.1", "react/socket": "^0.5", - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "~4.8", + "react/stream": "^0.6" } } diff --git a/examples/03-netcat.php b/examples/03-netcat.php index 42c1234..6ee70fa 100644 --- a/examples/03-netcat.php +++ b/examples/03-netcat.php @@ -3,7 +3,8 @@ use React\EventLoop\Factory; use React\SocketClient\Connector; use React\SocketClient\ConnectionInterface; -use React\Stream\Stream; +use React\Stream\ReadableResourceStream; +use React\Stream\WritableResourceStream; require __DIR__ . '/../vendor/autoload.php'; @@ -15,12 +16,10 @@ $loop = Factory::create(); $connector = new Connector($loop); -$stdin = new Stream(STDIN, $loop); +$stdin = new ReadableResourceStream(STDIN, $loop); $stdin->pause(); -$stdout = new Stream(STDOUT, $loop); -$stdout->pause(); -$stderr = new Stream(STDERR, $loop); -$stderr->pause(); +$stdout = new WritableResourceStream(STDOUT, $loop); +$stderr = new WritableResourceStream(STDERR, $loop); $stderr->write('Connecting' . PHP_EOL); diff --git a/examples/04-web.php b/examples/04-web.php index faaf5ed..ab5a68d 100644 --- a/examples/04-web.php +++ b/examples/04-web.php @@ -3,7 +3,7 @@ use React\EventLoop\Factory; use React\SocketClient\ConnectionInterface; use React\SocketClient\Connector; -use React\Stream\Stream; +use React\Stream\WritableResourceStream; require __DIR__ . '/../vendor/autoload.php'; @@ -36,8 +36,7 @@ $resource .= '?' . $parts['query']; } -$stdout = new Stream(STDOUT, $loop); -$stdout->pause(); +$stdout = new WritableResourceStream(STDOUT, $loop); $connector->connect($target)->then(function (ConnectionInterface $connection) use ($resource, $host, $stdout) { $connection->pipe($stdout);