Skip to content

Commit 7fc5855

Browse files
authored
Merge pull request #24 from clue-labs/browser-before-loop
Make `Browser` second constructor argument, de-emphasize default loop
2 parents 8ca8624 + efea160 commit 7fc5855

File tree

3 files changed

+86
-91
lines changed

3 files changed

+86
-91
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ Its constructor simply requires the URL to the remote Server-Sent Events (SSE) e
4949
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php');
5050
```
5151

52-
This class takes an optional `LoopInterface|null $loop` parameter that can be used to
53-
pass the event loop instance to use for this object. You can use a `null` value
54-
here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
55-
This value SHOULD NOT be given unless you're sure you want to explicitly use a
56-
given event loop instance.
57-
5852
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
5953
proxy servers etc.), you can explicitly pass a custom instance of the
6054
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
@@ -74,9 +68,15 @@ $connector = new React\Socket\Connector([
7468
]);
7569
$browser = new React\Http\Browser($connector);
7670

77-
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', null, $browser);
71+
$es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $browser);
7872
```
7973

74+
This class takes an optional `LoopInterface|null $loop` parameter that can be used to
75+
pass the event loop instance to use for this object. You can use a `null` value
76+
here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
77+
This value SHOULD NOT be given unless you're sure you want to explicitly use a
78+
given event loop instance.
79+
8080
## Install
8181

8282
The recommended way to install this library is [through Composer](https://getcomposer.org).

src/EventSource.php

+42-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,52 @@ class EventSource extends EventEmitter
8282
private $reconnectTime = 3.0;
8383

8484
/**
85+
* The `EventSource` class is responsible for communication with the remote Server-Sent Events (SSE) endpoint.
86+
*
87+
* The `EventSource` object works very similar to the one found in common
88+
* web browsers. Unless otherwise noted, it follows the same semantics as defined
89+
* under https://html.spec.whatwg.org/multipage/server-sent-events.html
90+
*
91+
* Its constructor simply requires the URL to the remote Server-Sent Events (SSE) endpoint:
92+
*
93+
* ```php
94+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php');
95+
* ```
96+
*
97+
* If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
98+
* proxy servers etc.), you can explicitly pass a custom instance of the
99+
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
100+
* to the [`Browser`](https://github.com/reactphp/http#browser) instance
101+
* and pass it as an additional argument to the `EventSource` like this:
102+
*
103+
* ```php
104+
* $connector = new React\Socket\Connector([
105+
* 'dns' => '127.0.0.1',
106+
* 'tcp' => [
107+
* 'bindto' => '192.168.10.1:0'
108+
* ],
109+
* 'tls' => [
110+
* 'verify_peer' => false,
111+
* 'verify_peer_name' => false
112+
* ]
113+
* ]);
114+
* $browser = new React\Http\Browser($connector);
115+
*
116+
* $es = new Clue\React\EventSource\EventSource('https://example.com/stream.php', $browser);
117+
* ```
118+
*
119+
* This class takes an optional `LoopInterface|null $loop` parameter that can be used to
120+
* pass the event loop instance to use for this object. You can use a `null` value
121+
* here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
122+
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
123+
* given event loop instance.
124+
*
85125
* @param string $url
86-
* @param ?LoopInterface $loop
87126
* @param ?Browser $browser
127+
* @param ?LoopInterface $loop
88128
* @throws \InvalidArgumentException for invalid URL
89129
*/
90-
public function __construct($url, LoopInterface $loop = null, Browser $browser = null)
130+
public function __construct($url, Browser $browser = null, LoopInterface $loop = null)
91131
{
92132
$parts = parse_url($url);
93133
if (!isset($parts['scheme'], $parts['host']) || !in_array($parts['scheme'], array('http', 'https'))) {

0 commit comments

Comments
 (0)