Skip to content

Commit 40df2b4

Browse files
authored
Merge pull request #13 from clue-labs/buzz
Update to reactphp/http v1.0.0
2 parents 8c37dc3 + d2a0860 commit 40df2b4

4 files changed

Lines changed: 94 additions & 92 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ from any Server-Sent Events (SSE) server endpoint:
2121

2222
```php
2323
$loop = Factory::create();
24-
$es = new EventSource('https://example.com/stream.php', $loop);
24+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
2525

26-
$es->on('message', function (MessageEvent $message) {
26+
$es->on('message', function (Clue\React\EventSource\MessageEvent $message) {
2727
//$data = json_decode($message->data);
2828
var_dump($message);
2929
});
@@ -48,19 +48,19 @@ registers everything with the main [`EventLoop`](https://github.com/reactphp/eve
4848
in order to handle async HTTP requests.
4949

5050
```php
51-
$loop = \React\EventLoop\Factory::create();
51+
$loop = React\EventLoop\Factory::create();
5252

53-
$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
53+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
5454
```
5555

5656
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
5757
proxy servers etc.), you can explicitly pass a custom instance of the
5858
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
59-
to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
59+
to the [`Browser`](https://github.com/reactphp/http#browser) instance
6060
and pass it as an additional argument to the `EventSource` like this:
6161

6262
```php
63-
$connector = new \React\Socket\Connector($loop, array(
63+
$connector = new React\Socket\Connector($loop, array(
6464
'dns' => '127.0.0.1',
6565
'tcp' => array(
6666
'bindto' => '192.168.10.1:0'
@@ -70,9 +70,9 @@ $connector = new \React\Socket\Connector($loop, array(
7070
'verify_peer_name' => false
7171
)
7272
));
73-
$browser = new \Clue\React\Buzz\Browser($loop, $connector);
73+
$browser = new React\Http\Browser($loop, $connector);
7474

75-
$es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
75+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
7676
```
7777

7878
## Install

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
},
1919
"require": {
2020
"php": ">=5.4",
21-
"clue/buzz-react": "^2.5",
22-
"evenement/evenement": "^3.0 || ^2.0"
21+
"evenement/evenement": "^3.0 || ^2.0",
22+
"react/event-loop": "^1.0",
23+
"react/http": "^1.0"
2324
},
2425
"require-dev": {
2526
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"

src/EventSource.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Clue\React\EventSource;
44

5-
use Clue\React\Buzz\Browser;
65
use Evenement\EventEmitter;
76
use Psr\Http\Message\ResponseInterface;
87
use React\EventLoop\LoopInterface;
8+
use React\Http\Browser;
99
use React\Stream\ReadableStreamInterface;
1010

1111
/**
@@ -20,19 +20,19 @@
2020
* in order to handle async HTTP requests.
2121
*
2222
* ```php
23-
* $loop = \React\EventLoop\Factory::create();
23+
* $loop = React\EventLoop\Factory::create();
2424
*
25-
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
25+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop);
2626
* ```
2727
*
2828
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
2929
* proxy servers etc.), you can explicitly pass a custom instance of the
3030
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
31-
* to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance
31+
* to the [`Browser`](https://github.com/reactphp/http#browser) instance
3232
* and pass it as an additional argument to the `EventSource` like this:
3333
*
3434
* ```php
35-
* $connector = new \React\Socket\Connector($loop, array(
35+
* $connector = new React\Socket\Connector($loop, array(
3636
* 'dns' => '127.0.0.1',
3737
* 'tcp' => array(
3838
* 'bindto' => '192.168.10.1:0'
@@ -42,9 +42,9 @@
4242
* 'verify_peer_name' => false
4343
* )
4444
* ));
45-
* $browser = new \Clue\React\Buzz\Browser($loop, $connector);
45+
* $browser = new React\Http\Browser($loop, $connector);
4646
*
47-
* $es = new \Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
47+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $loop, $browser);
4848
* ```
4949
*/
5050
class EventSource extends EventEmitter
@@ -88,7 +88,7 @@ public function __construct($url, LoopInterface $loop, Browser $browser = null)
8888
if ($browser === null) {
8989
$browser = new Browser($loop);
9090
}
91-
$this->browser = $browser->withOptions(array('streaming' => true, 'obeySuccessCode' => false));
91+
$this->browser = $browser->withRejectErrorResponse(false);
9292
$this->loop = $loop;
9393
$this->url = $url;
9494

@@ -106,7 +106,8 @@ private function request()
106106
$headers['Last-Event-ID'] = $this->lastEventId;
107107
}
108108

109-
$this->request = $this->browser->get(
109+
$this->request = $this->browser->requestStreaming(
110+
'GET',
110111
$this->url,
111112
$headers
112113
);

0 commit comments

Comments
 (0)