@@ -157,10 +157,10 @@ test,1,24
157157``` php
158158$stdin = new ReadableResourceStream(STDIN);
159159
160- $stream = new Decoder($stdin);
160+ $csv = new Decoder($stdin);
161161
162- $stream ->on('data', function ($data) {
163- // data is a parsed element from the CSV stream
162+ $csv ->on('data', function ($data) {
163+ // $ data is a parsed element from the CSV stream
164164 // line 1: $data = array('test', '1', '24');
165165 // line 2: $data = array('hello world', '2', '48');
166166 var_dump($data);
@@ -179,9 +179,9 @@ use a quote enclosure character (`"`) and a backslash escape character (`\`).
179179This behavior can be controlled through the optional constructor parameters:
180180
181181``` php
182- $stream = new Decoder($stdin, ';');
182+ $csv = new Decoder($stdin, ';');
183183
184- $stream ->on('data', function ($data) {
184+ $csv ->on('data', function ($data) {
185185 // CSV fields will now be delimited by semicolon
186186});
187187```
@@ -193,15 +193,15 @@ unreasonably long lines. It accepts an additional argument if you want to change
193193this from the default of 64 KiB:
194194
195195``` php
196- $stream = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
196+ $csv = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
197197```
198198
199199If the underlying stream emits an ` error ` event or the plain stream contains
200200any data that does not represent a valid CSV stream,
201201it will emit an ` error ` event and then ` close ` the input stream:
202202
203203``` php
204- $stream ->on('error', function (Exception $error) {
204+ $csv ->on('error', function (Exception $error) {
205205 // an error occured, stream will close next
206206});
207207```
@@ -212,7 +212,7 @@ followed by an `end` event on success or an `error` event for
212212incomplete/invalid CSV data as above:
213213
214214``` php
215- $stream ->on('end', function () {
215+ $csv ->on('end', function () {
216216 // stream successfully ended, stream will close next
217217});
218218```
@@ -221,7 +221,7 @@ If either the underlying stream or the `Decoder` is closed, it will forward
221221the ` close ` event:
222222
223223``` php
224- $stream ->on('close', function () {
224+ $csv ->on('close', function () {
225225 // stream closed
226226 // possibly after an "end" event or due to an "error" event
227227});
@@ -231,7 +231,7 @@ The `close(): void` method can be used to explicitly close the `Decoder` and
231231its underlying stream:
232232
233233``` php
234- $stream ->close();
234+ $csv ->close();
235235```
236236
237237The ` pipe(WritableStreamInterface $dest, array $options = array(): WritableStreamInterface `
@@ -240,7 +240,7 @@ Please note that the `Decoder` emits decoded/parsed data events, while many
240240(most?) writable streams expect only data chunks:
241241
242242``` php
243- $stream ->pipe($logger);
243+ $csv ->pipe($logger);
244244```
245245
246246For more details, see ReactPHP's
@@ -263,9 +263,9 @@ test,1
263263``` php
264264$stdin = new ReadableResourceStream(STDIN);
265265
266- $stream = new AssocDecoder($stdin);
266+ $csv = new AssocDecoder($stdin);
267267
268- $stream ->on('data', function ($data) {
268+ $csv ->on('data', function ($data) {
269269 // $data is a parsed element from the CSV stream
270270 // line 1: $data = array('name' => 'test', 'id' => '1');
271271 // line 2: $data = array('name' => 'hello world', 'id' => '2');
@@ -285,7 +285,7 @@ assoc arrays. After receiving the name of headers, this class will always emit
285285a ` headers ` event with a list of header names.
286286
287287``` php
288- $stream ->on('headers', function (array $headers) {
288+ $csv ->on('headers', function (array $headers) {
289289 // header line: $headers = array('name', 'id');
290290 var_dump($headers);
291291});
@@ -314,10 +314,10 @@ CSV elements instead of just chunks of strings:
314314``` php
315315$stdout = new WritableResourceStream(STDOUT);
316316
317- $stream = new Encoder($stdout);
317+ $csv = new Encoder($stdout);
318318
319- $stream ->write(array('test', true, 24));
320- $stream ->write(array('hello world', 2, 48));
319+ $csv ->write(array('test', true, 24));
320+ $csv ->write(array('hello world', 2, 48));
321321```
322322```
323323test,1,24
@@ -332,9 +332,9 @@ a Unix-style EOL (`\n` or `LF`).
332332This behavior can be controlled through the optional constructor parameters:
333333
334334``` php
335- $stream = new Encoder($stdout, ';');
335+ $csv = new Encoder($stdout, ';');
336336
337- $stream ->write(array('hello', 'world'));
337+ $csv ->write(array('hello', 'world'));
338338```
339339```
340340hello;world
@@ -345,7 +345,7 @@ any data that can not be represented as a valid CSV stream,
345345it will emit an ` error ` event and then ` close ` the input stream:
346346
347347``` php
348- $stream ->on('error', function (Exception $error) {
348+ $csv ->on('error', function (Exception $error) {
349349 // an error occured, stream will close next
350350});
351351```
@@ -354,7 +354,7 @@ If either the underlying stream or the `Encoder` is closed, it will forward
354354the ` close ` event:
355355
356356``` php
357- $stream ->on('close', function () {
357+ $csv ->on('close', function () {
358358 // stream closed
359359 // possibly after an "end" event or due to an "error" event
360360});
@@ -364,14 +364,14 @@ The `end(mixed $data = null): void` method can be used to optionally emit
364364any final data and then soft-close the ` Encoder ` and its underlying stream:
365365
366366``` php
367- $stream ->end();
367+ $csv ->end();
368368```
369369
370370The ` close(): void ` method can be used to explicitly close the ` Encoder ` and
371371its underlying stream:
372372
373373``` php
374- $stream ->close();
374+ $csv ->close();
375375```
376376
377377For more details, see ReactPHP's
0 commit comments