Skip to content

Commit 9c23823

Browse files
committed
Use full namespaces for documentation and minor clean up
1 parent f51216f commit 9c23823

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# clue/reactphp-ndjson
22

3-
[![CI status](https://github.com/clue/reactphp-ndjson/workflows/CI/badge.svg)](https://github.com/clue/reactphp-ndjson/actions)
3+
[![CI status](https://github.com/clue/reactphp-ndjson/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-ndjson/actions)
44
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/ndjson-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/ndjson-react)
55

66
Streaming newline-delimited JSON ([NDJSON](http://ndjson.org/)) parser and encoder for [ReactPHP](https://reactphp.org/).
@@ -10,7 +10,7 @@ file to store any kind of (uniform) structured data, such as a list of user
1010
objects or log entries. It uses a simple newline character between each
1111
individual record and as such can be both used for efficient persistence and
1212
simple append-style operations. This also allows it to be used in a streaming
13-
context, such as a simple inter-process commmunication (IPC) protocol or for a
13+
context, such as a simple inter-process communication (IPC) protocol or for a
1414
remote procedure call (RPC) mechanism. This library provides a simple
1515
streaming API to process very large NDJSON files with thousands or even millions
1616
of rows efficiently without having to load the whole file into memory at once.
@@ -39,7 +39,7 @@ of rows efficiently without having to load the whole file into memory at once.
3939

4040
## Support us
4141

42-
We invest a lot of time developing, maintaining and updating our awesome
42+
We invest a lot of time developing, maintaining, and updating our awesome
4343
open-source projects. You can help us sustain this high-quality of our work by
4444
[becoming a sponsor on GitHub](https://github.com/sponsors/clue). Sponsors get
4545
numerous benefits in return, see our [sponsoring page](https://github.com/sponsors/clue)
@@ -75,7 +75,7 @@ no "outer array" to be modified). This makes it a perfect fit for a streaming
7575
context, for line-oriented CLI tools (such as `grep` and others) or for a logging
7676
context where you want to append records at a later time. Additionally, this
7777
also allows it to be used in a streaming context, such as a simple inter-process
78-
commmunication (IPC) protocol or for a remote procedure call (RPC) mechanism.
78+
communication (IPC) protocol or for a remote procedure call (RPC) mechanism.
7979

8080
The newline character at the end of each line allows for some really simple
8181
*framing* (detecting individual records). While each individual line is valid
@@ -134,12 +134,12 @@ as parsed values instead of just chunks of strings:
134134
```
135135

136136
```php
137-
$stdin = new ReadableResourceStream(STDIN);
137+
$stdin = new React\Stream\ReadableResourceStream(STDIN);
138138

139-
$ndjson = new Decoder($stdin);
139+
$ndjson = new Clue\React\NDJson\Decoder($stdin);
140140

141141
$ndjson->on('data', function ($data) {
142-
// data is a parsed element from the JSON stream
142+
// $data is a parsed element from the JSON stream
143143
// line 1: $data = (object)array('name' => 'test', 'active' => true);
144144
// line 2: $data = (object)array('name' => 'hello wörld', 'active' => true);
145145
var_dump($data);
@@ -157,7 +157,7 @@ This means that, by default, JSON objects will be emitted as a `stdClass`.
157157
This behavior can be controlled through the optional constructor parameters:
158158

159159
```php
160-
$ndjson = new Decoder($stdin, true);
160+
$ndjson = new Clue\React\NDJson\Decoder($stdin, true);
161161

162162
$ndjson->on('data', function ($data) {
163163
// JSON objects will be emitted as assoc arrays now
@@ -171,7 +171,7 @@ unreasonably long lines. It accepts an additional argument if you want to change
171171
this from the default of 64 KiB:
172172

173173
```php
174-
$ndjson = new Decoder($stdin, false, 512, 0, 64 * 1024);
174+
$ndjson = new Clue\React\NDJson\Decoder($stdin, false, 512, 0, 64 * 1024);
175175
```
176176

177177
If the underlying stream emits an `error` event or the plain stream contains
@@ -234,9 +234,9 @@ and accepts its data through the same interface, but handles any data as complet
234234
JSON elements instead of just chunks of strings:
235235

236236
```php
237-
$stdout = new WritableResourceStream(STDOUT);
237+
$stdout = new React\Stream\WritableResourceStream(STDOUT);
238238

239-
$ndjson = new Encoder($stdout);
239+
$ndjson = new Clue\React\NDJson\Encoder($stdout);
240240

241241
$ndjson->write(array('name' => 'test', 'active' => true));
242242
$ndjson->write(array('name' => 'hello wörld', 'active' => true));
@@ -248,11 +248,11 @@ $ndjson->write(array('name' => 'hello wörld', 'active' => true));
248248

249249
The `Encoder` supports the same parameters as the underlying
250250
[`json_encode()`](https://www.php.net/manual/en/function.json-encode.php) function.
251-
This means that, by default, unicode characters will be escaped in the output.
251+
This means that, by default, Unicode characters will be escaped in the output.
252252
This behavior can be controlled through the optional constructor parameters:
253253

254254
```php
255-
$ndjson = new Encoder($stdout, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
255+
$ndjson = new Clue\React\NDJson\Encoder($stdout, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
256256

257257
$ndjson->write('hello wörld');
258258
```
@@ -302,7 +302,7 @@ For more details, see ReactPHP's
302302

303303
## Install
304304

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

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

322322
## Tests
323323

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

327327
```bash
328328
$ composer install
@@ -331,7 +331,7 @@ $ composer install
331331
To run the test suite, go to the project root and run:
332332

333333
```bash
334-
$ php vendor/bin/phpunit
334+
$ vendor/bin/phpunit
335335
```
336336

337337
## License

examples/91-benchmark-count.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414
// 3) pipe NDJSON into benchmark script:
1515
// $ php examples/91-benchmark-count.php < title.ratings.ndjson
1616

17-
use Clue\React\NDJson\Decoder;
1817
use React\EventLoop\Loop;
19-
use React\Stream\ReadableResourceStream;
2018

2119
require __DIR__ . '/../vendor/autoload.php';
2220

2321
if (extension_loaded('xdebug')) {
2422
echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL;
2523
}
2624

27-
$ndjson = new Decoder(new ReadableResourceStream(STDIN), true);
25+
$ndjson = new Clue\React\NDJson\Decoder(new React\Stream\ReadableResourceStream(STDIN), true);
2826

2927
$count = 0;
3028
$ndjson->on('data', function () use (&$count) {

examples/validate.php

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

33
// $ php examples/validate.php < examples/users.ndjson
44

5-
use Clue\React\NDJson\Decoder;
6-
use Clue\React\NDJson\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

18-
$ndjson = new Decoder($in);
19-
$encoder = new Encoder($out);
14+
$ndjson = new Clue\React\NDJson\Decoder($in);
15+
$encoder = new Clue\React\NDJson\Encoder($out);
2016
$ndjson->pipe($encoder);
2117

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

0 commit comments

Comments
 (0)