{"id":13828487,"url":"https://github.com/sergiorodenas/stream-parser","last_synced_at":"2025-04-08T00:38:44.205Z","repository":{"id":54872195,"uuid":"133578467","full_name":"sergiorodenas/stream-parser","owner":"sergiorodenas","description":"⚡ PHP7 / Laravel Multi-format Streaming Parser","archived":false,"fork":false,"pushed_at":"2024-03-19T02:17:11.000Z","size":66,"stargazers_count":438,"open_issues_count":7,"forks_count":45,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-08-04T09:08:29.347Z","etag":null,"topics":["collections","csv","json","laravel","parser","php","streaming","xml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergiorodenas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"sergiorodenas","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-05-15T22:07:36.000Z","updated_at":"2024-07-09T14:22:50.000Z","dependencies_parsed_at":"2024-06-18T15:21:03.262Z","dependency_job_id":null,"html_url":"https://github.com/sergiorodenas/stream-parser","commit_stats":{"total_commits":46,"total_committers":12,"mean_commits":"3.8333333333333335","dds":0.3695652173913043,"last_synced_commit":"13ed3833b3735966888eb5c770b5486b00b70748"},"previous_names":["rodenastyle/stream-parser"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiorodenas%2Fstream-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiorodenas%2Fstream-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiorodenas%2Fstream-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiorodenas%2Fstream-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergiorodenas","download_url":"https://codeload.github.com/sergiorodenas/stream-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755560,"owners_count":20990620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collections","csv","json","laravel","parser","php","streaming","xml"],"created_at":"2024-08-04T09:02:48.969Z","updated_at":"2025-04-08T00:38:44.175Z","avatar_url":"https://github.com/sergiorodenas.png","language":"PHP","funding_links":["https://patreon.com/sergiorodenas"],"categories":["PHP"],"sub_categories":[],"readme":"# ⚡ PHP7 / Laravel Multi-format Streaming Parser\n\n[![Build Status](https://scrutinizer-ci.com/g/Rodenastyle/stream-parser/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Rodenastyle/stream-parser/build-status/master)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/rodenastyle/stream-parser.svg?style=flat-square)](https://packagist.org/packages/rodenastyle/stream-parser)\n[![Quality Score](https://img.shields.io/scrutinizer/g/rodenastyle/stream-parser.svg?style=flat-square)](https://scrutinizer-ci.com/g/Rodenastyle/stream-parser/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/Rodenastyle/stream-parser/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Rodenastyle/stream-parser/?branch=master)\n[![License](https://img.shields.io/packagist/l/Rodenastyle/stream-parser.svg)](https://packagist.org/packages/Rodenastyle/stream-parser)\n\n\u003e When it comes to parsing XML/CSV/JSON/... documents, there are 2 approaches to consider:\n\u003e\n\u003e **DOM loading**: loads all the document, making it easy to navigate and parse, and as such provides maximum flexibility for developers.\n\u003e\n\u003e **Streaming**: implies iterating through the document, acts like a cursor and stops at each element in its way, thus avoiding memory overkill.\n\u003e\n\u003e [https://www.linkedin.com/pulse/processing-xml-documents-dom-vs-streaming-marius-ilina/](https://www.linkedin.com/pulse/processing-xml-documents-dom-vs-streaming-marius-ilina)\n\nThus, when it comes to big files, callbacks will be executed meanwhile file is downloading and will be much more efficient as far as memory is concerned.\n\n## Installation\n```\ncomposer require rodenastyle/stream-parser\n```\n\n## Recommended usage\nDelegate as possible the callback execution so it doesn't blocks the document reading: \n\n(Laravel Queue based example)\n```php\nuse Illuminate\\Support\\Collection;\n\nStreamParser::xml(\"https://example.com/users.xml\")-\u003eeach(function(Collection $user){\n    dispatch(new App\\Jobs\\SendEmail($user));\n});\n```\n\n## Practical Input/Code/Output demos\n\n### XML\n```xml\n\u003cbookstore\u003e\n    \u003cbook ISBN=\"10-000000-001\"\u003e\n        \u003ctitle\u003eThe Iliad and The Odyssey\u003c/title\u003e\n        \u003cprice\u003e12.95\u003c/price\u003e\n        \u003ccomments\u003e\n            \u003cuserComment rating=\"4\"\u003e\n                Best translation I've read.\n            \u003c/userComment\u003e\n            \u003cuserComment rating=\"2\"\u003e\n                I like other versions better.\n            \u003c/userComment\u003e\n        \u003c/comments\u003e\n    \u003c/book\u003e\n    [...]\n\u003c/bookstore\u003e\n```\n```php\nuse Illuminate\\Support\\Collection;\n\nStreamParser::xml(\"https://example.com/books.xml\")-\u003eeach(function(Collection $book){\n    var_dump($book);\n    var_dump($book-\u003eget('comments')-\u003etoArray());\n});\n```\n```\nclass Tightenco\\Collect\\Support\\Collection#19 (1) {\n  protected $items =\u003e\n  array(4) {\n    'ISBN' =\u003e\n    string(13) \"10-000000-001\"\n    'title' =\u003e\n    string(25) \"The Iliad and The Odyssey\"\n    'price' =\u003e\n    string(5) \"12.95\"\n    'comments' =\u003e\n    class Tightenco\\Collect\\Support\\Collection#17 (1) {\n      protected $items =\u003e\n      array(2) {\n        ...\n      }\n    }\n  }\n}\narray(2) {\n  [0] =\u003e\n  array(2) {\n    'rating' =\u003e\n    string(1) \"4\"\n    'userComment' =\u003e\n    string(27) \"Best translation I've read.\"\n  }\n  [1] =\u003e\n  array(2) {\n    'rating' =\u003e\n    string(1) \"2\"\n    'userComment' =\u003e\n    string(29) \"I like other versions better.\"\n  }\n}\n```\nAdditionally, you could make use of ```-\u003ewithSeparatedParametersList()``` to get the params of each element separated on the ```__params``` property.\nAlso, ```-\u003ewithoutSkippingFirstElement()``` could be of help to parse the very first item (usually the element that contains the elements).\n\n### JSON\n```json\n[\n  {\n    \"title\": \"The Iliad and The Odyssey\",\n    \"price\": 12.95,\n    \"comments\": [\n      {\"comment\": \"Best translation I've read.\"},\n      {\"comment\": \"I like other versions better.\"}\n    ]\n  },\n  {\n    \"title\": \"Anthology of World Literature\",\n    \"price\": 24.95,\n    \"comments\": [\n      {\"comment\": \"Needs more modern literature.\"},\n      {\"comment\": \"Excellent overview of world literature.\"}\n    ]\n  }\n]\n```\n```php\nuse Illuminate\\Support\\Collection;\n\nStreamParser::json(\"https://example.com/books.json\")-\u003eeach(function(Collection $book){\n    var_dump($book-\u003eget('comments')-\u003ecount());\n});\n```\n```\nint(2)\nint(2)\n```\n### CSV\n```csv\ntitle,price,comments\nThe Iliad and The Odyssey,12.95,\"Best translation I've read.,I like other versions better.\"\nAnthology of World Literature,24.95,\"Needs more modern literature.,Excellent overview of world literature.\"\n```\n```php\nuse Illuminate\\Support\\Collection;\n\nStreamParser::csv(\"https://example.com/books.csv\")-\u003eeach(function(Collection $book){\n    var_dump($book-\u003eget('comments')-\u003elast());\n});\n```\n```\nstring(29) \"I like other versions better.\"\nstring(39) \"Excellent overview of world literature.\"\n```\n\n## License\nThis library is released under [MIT](http://www.tldrlegal.com/license/mit-license) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiorodenas%2Fstream-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergiorodenas%2Fstream-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiorodenas%2Fstream-parser/lists"}