Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library should not be tied to specific data reading protocols #18

Closed
Bilge opened this issue Nov 21, 2019 · 1 comment
Closed

Library should not be tied to specific data reading protocols #18

Bilge opened this issue Nov 21, 2019 · 1 comment

Comments

@Bilge
Copy link

Bilge commented Nov 21, 2019

This library should not have either of the methods: fromFile() nor fromStream(). Perhaps these could be kept around as a convenience, but a pure implementation should not have methods that deal with reading files or streams, because insodoing, the library only supports files and streams. If I wanted to use this library with a general purpose async framework like Amp or React, I can't, because it doesn't explicitly support them. A well designed implementation would not tie itself to particular data protocols, instead just accepting incomplete JSON fragments from a string buffer, like Duct.

@halaxa
Copy link
Owner

halaxa commented Nov 21, 2019

Luckily Json machine is not tied to any data protocol. Those methods are just convenient methods. If you look inside any of the from* methods, you'll see how it's done. Core implementation is based on an iterable which is internally consumed by foreach. You can pass it any iterable that produces chunks of json document. Example:

$jsonDocumentChunks = ['{', '"one": "two"', '}']; // or any iterable, be it array, Iterator or Generator
$iterator = new JsonMachine($jsonDocumentChunks);
foreach ($iterator as $item) {
    // ...
}

@Bilge, if you want to contribute to README with an example of usage with Amp or React, feel free to do so. It will be appreciated.

@halaxa halaxa closed this as completed Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants