Skip to content

Commit 852cb6a

Browse files
committed
Use full namespaces for documentation and minor clean up
1 parent 725a6a7 commit 852cb6a

7 files changed

+42
-61
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ such as a list of user records or log entries. CSV is not exactly a new format
1111
and has been used in a large number of systems for decades. In particular, CSV
1212
is often used for historical reasons and despite its shortcomings, it is still a
1313
very common export format for a large number of tools to interface with
14-
spreadsheet processors (such as Exel, Calc etc.). This library provides a simple
14+
spreadsheet processors (such as Excel, Calc etc.). This library provides a simple
1515
streaming API to process very large CSV files with thousands or even millions of
1616
rows efficiently without having to load the whole file into memory at once.
1717

@@ -40,7 +40,7 @@ rows efficiently without having to load the whole file into memory at once.
4040

4141
## Support us
4242

43-
We invest a lot of time developing, maintaining and updating our awesome
43+
We invest a lot of time developing, maintaining, and updating our awesome
4444
open-source projects. You can help us sustain this high-quality of our work by
4545
[becoming a sponsor on GitHub](https://github.com/sponsors/clue). Sponsors get
4646
numerous benefits in return, see our [sponsoring page](https://github.com/sponsors/clue)
@@ -96,9 +96,9 @@ World!"
9696
started using some CSV-variant long before this standard was defined.
9797

9898
Some applications refer to CSV as Character-Separated Values, simply because
99-
using another delimiter (such as semicolon or tab) is a rather common approach
99+
using another delimiter (such as a semicolon or tab) is a rather common approach
100100
to avoid the need to enclose common values in quotes. This is particularly
101-
common for systems in Europe (and elsewhere) that use a comma as decimal separator.
101+
common for systems in Europe (and elsewhere) that use a comma as a decimal separator.
102102

103103
```
104104
name;comment
@@ -115,7 +115,7 @@ consistently.
115115

116116
Despite its shortcomings, CSV is widely used and this is unlikely to change any
117117
time soon. In particular, CSV is a very common export format for a lot of tools
118-
to interface with spreadsheet processors (such as Exel, Calc etc.). This means
118+
to interface with spreadsheet processors (such as Excel, Calc etc.). This means
119119
that CSV is often used for historical reasons and using CSV to store structured
120120
application data is usually not a good idea nowadays – but exporting to CSV for
121121
known applications continues to be a very reasonable approach.
@@ -155,11 +155,11 @@ test,1,24
155155
"hello world",2,48
156156
```
157157
```php
158-
$stdin = new ReadableResourceStream(STDIN);
158+
$stdin = new React\Stream\ReadableResourceStream(STDIN);
159159

160-
$csv = new Decoder($stdin);
160+
$csv = new Clue\React\Csv\Decoder($stdin);
161161

162-
$csv->on('data', function ($data) {
162+
$csv->on('data', function (array $data) {
163163
// $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');
@@ -179,9 +179,9 @@ use a quote enclosure character (`"`) and a backslash escape character (`\`).
179179
This behavior can be controlled through the optional constructor parameters:
180180

181181
```php
182-
$csv = new Decoder($stdin, ';');
182+
$csv = new Clue\React\Csv\Decoder($stdin, ';');
183183

184-
$csv->on('data', function ($data) {
184+
$csv->on('data', function (array $data) {
185185
// CSV fields will now be delimited by semicolon
186186
});
187187
```
@@ -193,7 +193,7 @@ unreasonably long lines. It accepts an additional argument if you want to change
193193
this from the default of 64 KiB:
194194

195195
```php
196-
$csv = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
196+
$csv = new Clue\React\Csv\Decoder($stdin, ',', '"', '\\', 64 * 1024);
197197
```
198198

199199
If the underlying stream emits an `error` event or the plain stream contains
@@ -261,11 +261,11 @@ test,1
261261
"hello world",2
262262
```
263263
```php
264-
$stdin = new ReadableResourceStream(STDIN);
264+
$stdin = new React\Stream\ReadableResourceStream(STDIN);
265265

266-
$csv = new AssocDecoder($stdin);
266+
$csv = new Clue\React\Csv\AssocDecoder($stdin);
267267

268-
$csv->on('data', function ($data) {
268+
$csv->on('data', function (array $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');
@@ -312,9 +312,9 @@ and accepts its data through the same interface, but handles any data as complet
312312
CSV elements instead of just chunks of strings:
313313

314314
```php
315-
$stdout = new WritableResourceStream(STDOUT);
315+
$stdout = new React\Stream\WritableResourceStream(STDOUT);
316316

317-
$csv = new Encoder($stdout);
317+
$csv = new Clue\React\Csv\Encoder($stdout);
318318

319319
$csv->write(array('test', true, 24));
320320
$csv->write(array('hello world', 2, 48));
@@ -332,7 +332,7 @@ a Unix-style EOL (`\n` or `LF`).
332332
This behavior can be controlled through the optional constructor parameters:
333333

334334
```php
335-
$csv = new Encoder($stdout, ';');
335+
$csv = new Clue\React\Csv\Encoder($stdout, ';');
336336

337337
$csv->write(array('hello', 'world'));
338338
```
@@ -379,7 +379,7 @@ For more details, see ReactPHP's
379379

380380
## Install
381381

382-
The recommended way to install this library is [through Composer](https://getcomposer.org).
382+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
383383
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
384384

385385
This project follows [SemVer](https://semver.org/).
@@ -394,12 +394,12 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
394394
This project aims to run on any platform and thus does not require any PHP
395395
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
396396
HHVM.
397-
It's *highly recommended to use the latest supported PHP version PHP 7+* for this project.
397+
It's *highly recommended to use the latest supported PHP version* for this project.
398398

399399
## Tests
400400

401401
To run the test suite, you first need to clone this repo and then install all
402-
dependencies [through Composer](https://getcomposer.org):
402+
dependencies [through Composer](https://getcomposer.org/):
403403

404404
```bash
405405
$ composer install
@@ -408,7 +408,7 @@ $ composer install
408408
To run the test suite, go to the project root and run:
409409

410410
```bash
411-
$ php vendor/bin/phpunit
411+
$ vendor/bin/phpunit
412412
```
413413

414414
## License

examples/01-count.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
// $ php examples/01-count.php < examples/users.csv
44

5-
use Clue\React\Csv\AssocDecoder;
65
use React\EventLoop\Loop;
7-
use React\Stream\ReadableResourceStream;
8-
use React\Stream\WritableResourceStream;
96

107
require __DIR__ . '/../vendor/autoload.php';
118

129
$exit = 0;
13-
$in = new ReadableResourceStream(STDIN);
14-
$info = new WritableResourceStream(STDERR);
10+
$in = new React\Stream\ReadableResourceStream(STDIN);
11+
$info = new React\Stream\WritableResourceStream(STDERR);
1512

1613
$delimiter = isset($argv[1]) ? $argv[1] : ',';
1714

18-
$csv = new AssocDecoder($in, $delimiter);
15+
$csv = new Clue\React\Csv\AssocDecoder($in, $delimiter);
1916

2017
$count = 0;
2118
$csv->on('data', function () use (&$count) {

examples/02-validate.php

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

33
// $ php examples/02-validate.php < examples/users.csv
44

5-
use Clue\React\Csv\Decoder;
6-
use Clue\React\Csv\Encoder;
75
use React\EventLoop\Loop;
8-
use React\Stream\ReadableResourceStream;
9-
use React\Stream\WritableResourceStream;
106

117
require __DIR__ . '/../vendor/autoload.php';
128

139
$exit = 0;
14-
$in = new ReadableResourceStream(STDIN);
15-
$out = new WritableResourceStream(STDOUT);
16-
$info = new WritableResourceStream(STDERR);
10+
$in = new React\Stream\ReadableResourceStream(STDIN);
11+
$out = new React\Stream\WritableResourceStream(STDOUT);
12+
$info = new React\Stream\WritableResourceStream(STDERR);
1713

1814
$delimiter = isset($argv[1]) ? $argv[1] : ',';
1915

20-
$csv = new Decoder($in, $delimiter);
21-
$encoder = new Encoder($out, $delimiter);
16+
$csv = new Clue\React\Csv\Decoder($in, $delimiter);
17+
$encoder = new Clue\React\Csv\Encoder($out, $delimiter);
2218
$csv->pipe($encoder);
2319

2420
$csv->on('error', function (Exception $e) use ($info, &$exit) {

examples/11-csv2ndjson.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
// $ php examples/11-csv2ndjson.php < examples/users.csv > examples/users.ndjson
44
// see also https://github.com/clue/reactphp-ndjson
55

6-
use Clue\React\Csv\AssocDecoder;
76
use React\EventLoop\Loop;
8-
use React\Stream\ReadableResourceStream;
9-
use React\Stream\WritableResourceStream;
10-
use React\Stream\ThroughStream;
117

128
require __DIR__ . '/../vendor/autoload.php';
139

1410
$exit = 0;
15-
$in = new ReadableResourceStream(STDIN);
16-
$out = new WritableResourceStream(STDOUT);
17-
$info = new WritableResourceStream(STDERR);
11+
$in = new React\Stream\ReadableResourceStream(STDIN);
12+
$out = new React\Stream\WritableResourceStream(STDOUT);
13+
$info = new React\Stream\WritableResourceStream(STDERR);
1814

1915
$delimiter = isset($argv[1]) ? $argv[1] : ',';
2016

21-
$csv = new AssocDecoder($in, $delimiter);
17+
$csv = new Clue\React\Csv\AssocDecoder($in, $delimiter);
2218

23-
$encoder = new ThroughStream(function ($data) {
19+
$encoder = new React\Stream\ThroughStream(function ($data) {
2420
$data = \array_filter($data, function ($one) {
2521
return ($one !== '');
2622
});

examples/12-csv2tsv.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
// $ php examples/12-csv2tsv.php < examples/users.csv > examples/users.tsv
44
// see also https://github.com/clue/reactphp-tsv
55

6-
use Clue\React\Csv\Decoder;
76
use React\EventLoop\Loop;
8-
use React\Stream\ReadableResourceStream;
9-
use React\Stream\WritableResourceStream;
10-
use React\Stream\ThroughStream;
117

128
require __DIR__ . '/../vendor/autoload.php';
139

1410
$exit = 0;
15-
$in = new ReadableResourceStream(STDIN);
16-
$out = new WritableResourceStream(STDOUT);
17-
$info = new WritableResourceStream(STDERR);
11+
$in = new React\Stream\ReadableResourceStream(STDIN);
12+
$out = new React\Stream\WritableResourceStream(STDOUT);
13+
$info = new React\Stream\WritableResourceStream(STDERR);
1814

1915
$delimiter = isset($argv[1]) ? $argv[1] : ',';
2016

21-
$csv = new Decoder($in, $delimiter);
17+
$csv = new Clue\React\Csv\Decoder($in, $delimiter);
2218

23-
$encoder = new ThroughStream(function ($data) {
19+
$encoder = new React\Stream\ThroughStream(function ($data) {
2420
$data = \array_map(function ($value) {
2521
return \addcslashes($value, "\0..\37");
2622
}, $data);

examples/91-benchmark-count.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
// 2) pipe CSV into benchmark script:
1111
// $ php examples/91-benchmark-count.php < IRAhandle_tweets_1.csv
1212

13-
use Clue\React\Csv\AssocDecoder;
1413
use React\EventLoop\Loop;
15-
use React\Stream\ReadableResourceStream;
1614

1715
require __DIR__ . '/../vendor/autoload.php';
1816

1917
if (extension_loaded('xdebug')) {
2018
echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL;
2119
}
2220

23-
$csv = new AssocDecoder(new ReadableResourceStream(STDIN));
21+
$csv = new Clue\React\Csv\AssocDecoder(new React\Stream\ReadableResourceStream(STDIN));
2422

2523
$count = 0;
2624
$csv->on('data', function () use (&$count) {

examples/92-benchmark-count-gzip.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// 3) pipe compressed CSV into benchmark script:
1111
// $ php examples/92-benchmark-count-gzip.php < IRAhandle_tweets_1.csv.gz
1212

13-
use Clue\React\Csv\AssocDecoder;
14-
use React\ChildProcess\Process;
1513
use React\EventLoop\Loop;
1614

1715
require __DIR__ . '/../vendor/autoload.php';
@@ -25,13 +23,13 @@
2523
// is preferred here. If the input source is slower (such as an HTTP download)
2624
// or if `gunzip` is not available (Windows), using a built-in decompressor
2725
// such as https://github.com/clue/reactphp-zlib would be preferable.
28-
$process = new Process('exec gunzip', null, null, array(
26+
$process = new React\ChildProcess\Process('exec gunzip', null, null, array(
2927
0 => STDIN,
3028
1 => array('pipe', 'w'),
3129
STDERR
3230
));
3331
$process->start();
34-
$csv = new AssocDecoder($process->stdout);
32+
$csv = new Clue\React\Csv\AssocDecoder($process->stdout);
3533

3634
$count = 0;
3735
$csv->on('data', function () use (&$count) {

0 commit comments

Comments
 (0)