@@ -82,12 +82,52 @@ class EventSource extends EventEmitter
82
82
private $ reconnectTime = 3.0 ;
83
83
84
84
/**
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
+ *
85
125
* @param string $url
86
- * @param ?LoopInterface $loop
87
126
* @param ?Browser $browser
127
+ * @param ?LoopInterface $loop
88
128
* @throws \InvalidArgumentException for invalid URL
89
129
*/
90
- public function __construct ($ url , LoopInterface $ loop = null , Browser $ browser = null )
130
+ public function __construct ($ url , Browser $ browser = null , LoopInterface $ loop = null )
91
131
{
92
132
$ parts = parse_url ($ url );
93
133
if (!isset ($ parts ['scheme ' ], $ parts ['host ' ]) || !in_array ($ parts ['scheme ' ], array ('http ' , 'https ' ))) {
0 commit comments