@@ -157,10 +157,10 @@ test,1,24
157
157
``` php
158
158
$stdin = new ReadableResourceStream(STDIN);
159
159
160
- $stream = new Decoder($stdin);
160
+ $csv = new Decoder($stdin);
161
161
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
164
164
// line 1: $data = array('test', '1', '24');
165
165
// line 2: $data = array('hello world', '2', '48');
166
166
var_dump($data);
@@ -179,9 +179,9 @@ use a quote enclosure character (`"`) and a backslash escape character (`\`).
179
179
This behavior can be controlled through the optional constructor parameters:
180
180
181
181
``` php
182
- $stream = new Decoder($stdin, ';');
182
+ $csv = new Decoder($stdin, ';');
183
183
184
- $stream ->on('data', function ($data) {
184
+ $csv ->on('data', function ($data) {
185
185
// CSV fields will now be delimited by semicolon
186
186
});
187
187
```
@@ -193,15 +193,15 @@ unreasonably long lines. It accepts an additional argument if you want to change
193
193
this from the default of 64 KiB:
194
194
195
195
``` php
196
- $stream = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
196
+ $csv = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
197
197
```
198
198
199
199
If the underlying stream emits an ` error ` event or the plain stream contains
200
200
any data that does not represent a valid CSV stream,
201
201
it will emit an ` error ` event and then ` close ` the input stream:
202
202
203
203
``` php
204
- $stream ->on('error', function (Exception $error) {
204
+ $csv ->on('error', function (Exception $error) {
205
205
// an error occured, stream will close next
206
206
});
207
207
```
@@ -212,7 +212,7 @@ followed by an `end` event on success or an `error` event for
212
212
incomplete/invalid CSV data as above:
213
213
214
214
``` php
215
- $stream ->on('end', function () {
215
+ $csv ->on('end', function () {
216
216
// stream successfully ended, stream will close next
217
217
});
218
218
```
@@ -221,7 +221,7 @@ If either the underlying stream or the `Decoder` is closed, it will forward
221
221
the ` close ` event:
222
222
223
223
``` php
224
- $stream ->on('close', function () {
224
+ $csv ->on('close', function () {
225
225
// stream closed
226
226
// possibly after an "end" event or due to an "error" event
227
227
});
@@ -231,7 +231,7 @@ The `close(): void` method can be used to explicitly close the `Decoder` and
231
231
its underlying stream:
232
232
233
233
``` php
234
- $stream ->close();
234
+ $csv ->close();
235
235
```
236
236
237
237
The ` pipe(WritableStreamInterface $dest, array $options = array(): WritableStreamInterface `
@@ -240,7 +240,7 @@ Please note that the `Decoder` emits decoded/parsed data events, while many
240
240
(most?) writable streams expect only data chunks:
241
241
242
242
``` php
243
- $stream ->pipe($logger);
243
+ $csv ->pipe($logger);
244
244
```
245
245
246
246
For more details, see ReactPHP's
@@ -263,9 +263,9 @@ test,1
263
263
``` php
264
264
$stdin = new ReadableResourceStream(STDIN);
265
265
266
- $stream = new AssocDecoder($stdin);
266
+ $csv = new AssocDecoder($stdin);
267
267
268
- $stream ->on('data', function ($data) {
268
+ $csv ->on('data', function ($data) {
269
269
// $data is a parsed element from the CSV stream
270
270
// line 1: $data = array('name' => 'test', 'id' => '1');
271
271
// 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
285
285
a ` headers ` event with a list of header names.
286
286
287
287
``` php
288
- $stream ->on('headers', function (array $headers) {
288
+ $csv ->on('headers', function (array $headers) {
289
289
// header line: $headers = array('name', 'id');
290
290
var_dump($headers);
291
291
});
@@ -314,10 +314,10 @@ CSV elements instead of just chunks of strings:
314
314
``` php
315
315
$stdout = new WritableResourceStream(STDOUT);
316
316
317
- $stream = new Encoder($stdout);
317
+ $csv = new Encoder($stdout);
318
318
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));
321
321
```
322
322
```
323
323
test,1,24
@@ -332,9 +332,9 @@ a Unix-style EOL (`\n` or `LF`).
332
332
This behavior can be controlled through the optional constructor parameters:
333
333
334
334
``` php
335
- $stream = new Encoder($stdout, ';');
335
+ $csv = new Encoder($stdout, ';');
336
336
337
- $stream ->write(array('hello', 'world'));
337
+ $csv ->write(array('hello', 'world'));
338
338
```
339
339
```
340
340
hello;world
@@ -345,7 +345,7 @@ any data that can not be represented as a valid CSV stream,
345
345
it will emit an ` error ` event and then ` close ` the input stream:
346
346
347
347
``` php
348
- $stream ->on('error', function (Exception $error) {
348
+ $csv ->on('error', function (Exception $error) {
349
349
// an error occured, stream will close next
350
350
});
351
351
```
@@ -354,7 +354,7 @@ If either the underlying stream or the `Encoder` is closed, it will forward
354
354
the ` close ` event:
355
355
356
356
``` php
357
- $stream ->on('close', function () {
357
+ $csv ->on('close', function () {
358
358
// stream closed
359
359
// possibly after an "end" event or due to an "error" event
360
360
});
@@ -364,14 +364,14 @@ The `end(mixed $data = null): void` method can be used to optionally emit
364
364
any final data and then soft-close the ` Encoder ` and its underlying stream:
365
365
366
366
``` php
367
- $stream ->end();
367
+ $csv ->end();
368
368
```
369
369
370
370
The ` close(): void ` method can be used to explicitly close the ` Encoder ` and
371
371
its underlying stream:
372
372
373
373
``` php
374
- $stream ->close();
374
+ $csv ->close();
375
375
```
376
376
377
377
For more details, see ReactPHP's
0 commit comments