From a4143d9e61e1baec797141c9b3ce8509e9b49911 Mon Sep 17 00:00:00 2001 From: Filip Halaxa Date: Thu, 29 Nov 2018 11:41:26 +0100 Subject: [PATCH] Renamed to JsonMachine --- README.md | 23 ++++++++++--------- composer.json | 7 +++--- src/Exception/InvalidArgumentException.php | 2 +- src/Exception/PathNotFoundException.php | 2 +- src/Exception/SyntaxError.php | 2 +- src/{JsonIterator.php => JsonMachine.php} | 6 ++--- src/Lexer.php | 2 +- src/Parser.php | 8 +++---- src/examples/guzzleHttp.php | 2 +- .../JsonMachineTest.json} | 0 .../JsonMachineTest.php} | 10 ++++---- .../LexerTest.php | 6 ++--- .../ParserTest.php | 12 +++++----- test/performance/testPerformace.php | 4 ++-- 14 files changed, 43 insertions(+), 43 deletions(-) rename src/{JsonIterator.php => JsonMachine.php} (91%) rename test/{JsonStreamReaderTest/JsonIteratorTest.json => JsonMachineTest/JsonMachineTest.json} (100%) rename test/{JsonStreamReaderTest/JsonIteratorTest.php => JsonMachineTest/JsonMachineTest.php} (62%) rename test/{JsonStreamReaderTest => JsonMachineTest}/LexerTest.php (88%) rename test/{JsonStreamReaderTest => JsonMachineTest}/ParserTest.php (95%) diff --git a/README.md b/README.md index 1618809..c6b73c4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ -# JSON Iterator +# JSON Machine -Json Iterator is a simple **JSON stream parser for PHP** based on coroutines, -developed for extremely large JSON datasets. Main features are: -- Speed. Performace critical code contains no unnecessary function calls, no regular expressions -and uses native `json_decode` to decode document chunks. -- Ease of use. Just iterate it with `foreach`. No events and callbacks. -- Supports iteration on any subtree of the document, specified by [Json Pointer](https://tools.ietf.org/html/rfc6901) +Json Machine is a Fast, efficient and easy-to-use JSON stream parser based on coroutines +developed for unpredictably long JSON streams or documents. Main features are: + +- Ease of use. Just iterate JSON of any size with `foreach`. No events and callbacks. - Constant memory footprint for unpredictably large JSON documents. +- Speed. Performace critical code contains no unnecessary function calls, no regular expressions +and uses native `json_decode` to decode JSON document chunks. +- Supports efficient iteration on any subtree of the document, specified by [Json Pointer](https://tools.ietf.org/html/rfc6901) ## Examples ### Parsing simple JSON document @@ -26,7 +27,7 @@ It can be parsed this way: ```php $data) { // 1st iteration: $name === "apple" and $data === ["color" => "red"] @@ -56,7 +57,7 @@ do it like this: ```php $data) { // The same as above, which means: // 1st iteration: $name === "apple" and $data === ["color" => "red"] @@ -64,14 +65,14 @@ foreach ($jsonStream as $name => $data) { } ``` -> Implementation detail: +> Note: > > Value of `fruits-key` is not loaded into memory at once, but only one item in > `fruits-key` at a time. It is always one item in memory at a time at the level/subtree > you are currently iterating. Thus the memory consumption is constant. ## Parsing API responses If you use this library to parse large API responses, all you need to do is passing the stream resource -of your api response to `JsonIterator::fromStream($streamResource)`. +of your api response to `JsonMachine::fromStream($streamResource)`. ### GuzzleHttp example Guzzle uses its own streams, but they can be converted back to PHP streams by calling `\GuzzleHttp\Psr7\StreamWrapper::getResource()`. See [GuzzleHttp example](src/examples/guzzleHttp.php) diff --git a/composer.json b/composer.json index 920e3f2..b1d8d25 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "jsonator/jsonator", - "description": "Json parser consuming a stream of json data with easy, iterable api.", + "name": "halaxa/json-machine", + "description": "Fast, efficient and easy-to-use JSON stream parser developed for unpredictably long JSON streams or documents.", "require": { "php": ">=5.6", "ext-json": "*" @@ -15,10 +15,9 @@ } ], "autoload" : { - "psr-4": {"JsonIterator\\": "src/"} + "psr-4": {"JsonMachine\\": "src/"} }, "suggest": { - "ext-curl": "To run scripts in src/examples.", "guzzlehttp/guzzle": "To run scripts in src/examples." } } diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 1025c5a..0abbdde 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -1,6 +1,6 @@ request('GET', 'https://httpbin.org/anything?key=value'); // Gets PHP stream resource from Guzzle stream $phpStream = \GuzzleHttp\Psr7\StreamWrapper::getResource($respose->getBody()); -$result = iterator_to_array(\JsonIterator\JsonIterator::fromStream($phpStream)); +$result = iterator_to_array(\JsonMachine\JsonMachine::fromStream($phpStream)); assert($result['args'] == ['key' => 'value']); diff --git a/test/JsonStreamReaderTest/JsonIteratorTest.json b/test/JsonMachineTest/JsonMachineTest.json similarity index 100% rename from test/JsonStreamReaderTest/JsonIteratorTest.json rename to test/JsonMachineTest/JsonMachineTest.json diff --git a/test/JsonStreamReaderTest/JsonIteratorTest.php b/test/JsonMachineTest/JsonMachineTest.php similarity index 62% rename from test/JsonStreamReaderTest/JsonIteratorTest.php rename to test/JsonMachineTest/JsonMachineTest.php index e6d8ae0..f808211 100644 --- a/test/JsonStreamReaderTest/JsonIteratorTest.php +++ b/test/JsonMachineTest/JsonMachineTest.php @@ -1,17 +1,17 @@ assertSame(["key" => "value"], iterator_to_array($iterator)); } @@ -20,7 +20,7 @@ class JsonIteratorTest extends \PHPUnit_Framework_TestCase return [ ['fromStream', fopen('data://text/plain,{"args": {"key":"value"}}', 'r'), '/args'], ['fromString', '{"args": {"key":"value"}}', '/args'], - ['fromFile', __DIR__ . '/JsonIteratorTest.json', '/args'], + ['fromFile', __DIR__ . '/JsonMachineTest.json', '/args'], ]; } } diff --git a/test/JsonStreamReaderTest/LexerTest.php b/test/JsonMachineTest/LexerTest.php similarity index 88% rename from test/JsonStreamReaderTest/LexerTest.php rename to test/JsonMachineTest/LexerTest.php index 9c35369..073441e 100644 --- a/test/JsonStreamReaderTest/LexerTest.php +++ b/test/JsonMachineTest/LexerTest.php @@ -1,9 +1,9 @@