diff --git a/README.md b/README.md index 910e64e..977fe32 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ as parsed values instead of just chunks of strings: ``` ```php -$stdin = new ReadableResourceStream(STDIN, $loop); +$stdin = new ReadableResourceStream(STDIN); $stream = new Decoder($stdin); @@ -234,7 +234,7 @@ and accepts its data through the same interface, but handles any data as complet JSON elements instead of just chunks of strings: ```php -$stdout = new WritableResourceStream(STDOUT, $loop); +$stdout = new WritableResourceStream(STDOUT); $stream = new Encoder($stdout); diff --git a/composer.json b/composer.json index 0f0ac48..bfe0073 100644 --- a/composer.json +++ b/composer.json @@ -10,18 +10,18 @@ "email": "christian@clue.engineering" } ], - "autoload": { - "psr-4": { "Clue\\React\\NDJson\\": "src/" } - }, - "autoload-dev": { - "psr-4": { "Clue\\Tests\\React\\NDJson\\": "tests/" } - }, "require": { "php": ">=5.3", - "react/stream": "^1.0 || ^0.7 || ^0.6" + "react/stream": "^1.2" }, "require-dev": { - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", + "react/event-loop": "^1.2", "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" + }, + "autoload": { + "psr-4": { "Clue\\React\\NDJson\\": "src/" } + }, + "autoload-dev": { + "psr-4": { "Clue\\Tests\\React\\NDJson\\": "tests/" } } } diff --git a/examples/91-benchmark-count.php b/examples/91-benchmark-count.php index 8ced80c..6b2cb26 100644 --- a/examples/91-benchmark-count.php +++ b/examples/91-benchmark-count.php @@ -15,7 +15,7 @@ // $ php examples/91-benchmark-count.php < title.ratings.ndjson use Clue\React\NDJson\Decoder; -use React\EventLoop\Factory; +use React\EventLoop\Loop; use React\Stream\ReadableResourceStream; require __DIR__ . '/../vendor/autoload.php'; @@ -24,8 +24,7 @@ echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL; } -$loop = Factory::create(); -$decoder = new Decoder(new ReadableResourceStream(STDIN, $loop), true); +$decoder = new Decoder(new ReadableResourceStream(STDIN), true); $count = 0; $decoder->on('data', function () use (&$count) { @@ -33,15 +32,13 @@ }); $start = microtime(true); -$report = $loop->addPeriodicTimer(0.05, function () use (&$count, $start) { +$report = Loop::addPeriodicTimer(0.05, function () use (&$count, $start) { printf("\r%d records in %0.3fs...", $count, microtime(true) - $start); }); -$decoder->on('close', function () use (&$count, $report, $loop, $start) { +$decoder->on('close', function () use (&$count, $report, $start) { $now = microtime(true); - $loop->cancelTimer($report); + Loop::cancelTimer($report); printf("\r%d records in %0.3fs => %d records/s\n", $count, $now - $start, $count / ($now - $start)); }); - -$loop->run(); diff --git a/examples/validate.php b/examples/validate.php index 352b24a..9fc847d 100644 --- a/examples/validate.php +++ b/examples/validate.php @@ -2,20 +2,18 @@ // $ php examples/validate.php < examples/users.ndjson -use React\EventLoop\Factory; -use React\Stream\ReadableResourceStream; -use React\Stream\WritableResourceStream; use Clue\React\NDJson\Decoder; use Clue\React\NDJson\Encoder; +use React\EventLoop\Loop; +use React\Stream\ReadableResourceStream; +use React\Stream\WritableResourceStream; require __DIR__ . '/../vendor/autoload.php'; -$loop = Factory::create(); - $exit = 0; -$in = new ReadableResourceStream(STDIN, $loop); -$out = new WritableResourceStream(STDOUT, $loop); -$info = new WritableResourceStream(STDERR, $loop); +$in = new ReadableResourceStream(STDIN); +$out = new WritableResourceStream(STDOUT); +$info = new WritableResourceStream(STDERR); $decoder = new Decoder($in); $encoder = new Encoder($out); @@ -30,6 +28,6 @@ $info->write('Valid NDJson will be forwarded to STDOUT' . PHP_EOL); $info->write('Invalid NDJson will raise an error on STDERR and exit with code 1' . PHP_EOL); -$loop->run(); +Loop::run(); exit($exit);