denis-kisel/stream-parser
Composer 安装命令:
composer require denis-kisel/stream-parser
包简介
PHP Multiformat Streaming Parser
README 文档
README
When it comes to parsing XML/CSV/JSON/... documents, there are 2 approaches to consider:
DOM loading: loads all the document, making it easy to navigate and parse, and as such provides maximum flexibility for developers.
Streaming: implies iterating through the document, acts like a cursor and stops at each element in its way, thus avoiding memory overkill.
Thus, 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.
Forked from rodenastyle
Installation
composer require denis-kisel/stream-parser
Recommended usage
Delegate as possible the callback execution so it doesn't blocks the document reading:
(Laravel Queue based example)
use Tightenco\Collect\Support\Collection; StreamParser::xml("https://example.com/users.xml")->each(function(Collection $user){ dispatch(new App\Jobs\SendEmail($user)); });
Practical Input/Code/Output demos
XML
<bookstore> <book ISBN="10-000000-001"> <title>The Iliad and The Odyssey</title> <price>12.95</price> <comments> <userComment rating="4"> Best translation I've read. </userComment> <userComment rating="2"> I like other versions better. </userComment> </comments> </book> [...] </bookstore>
use Tightenco\Collect\Support\Collection; StreamParser::xml("https://example.com/books.xml")->each(function(Collection $book){ var_dump($book); var_dump($book->get('comments')->toArray()); });
class Tightenco\Collect\Support\Collection#19 (1) {
protected $items =>
array(4) {
'ISBN' =>
string(13) "10-000000-001"
'title' =>
string(25) "The Iliad and The Odyssey"
'price' =>
string(5) "12.95"
'comments' =>
class Tightenco\Collect\Support\Collection#17 (1) {
protected $items =>
array(2) {
...
}
}
}
}
array(2) {
[0] =>
array(2) {
'rating' =>
string(1) "4"
'userComment' =>
string(27) "Best translation I've read."
}
[1] =>
array(2) {
'rating' =>
string(1) "2"
'userComment' =>
string(29) "I like other versions better."
}
}
JSON
[
{
"title": "The Iliad and The Odyssey",
"price": 12.95,
"comments": [
{"comment": "Best translation I've read."},
{"comment": "I like other versions better."}
]
},
{
"title": "Anthology of World Literature",
"price": 24.95,
"comments": [
{"comment": "Needs more modern literature."},
{"comment": "Excellent overview of world literature."}
]
}
]
use Tightenco\Collect\Support\Collection; StreamParser::json("https://example.com/books.json")->each(function(Collection $book){ var_dump($book->get('comments')->count()); });
int(2)
int(2)
CSV
title,price,comments
The Iliad and The Odyssey,12.95,"Best translation I've read.,I like other versions better."
Anthology of World Literature,24.95,"Needs more modern literature.,Excellent overview of world literature."
use Tightenco\Collect\Support\Collection; StreamParser::csv("https://example.com/books.csv")->each(function(Collection $book){ var_dump($book->get('comments')->last()); });
string(29) "I like other versions better."
string(39) "Excellent overview of world literature."
License
This library is released under MIT license.
denis-kisel/stream-parser 适用场景与选型建议
denis-kisel/stream-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「xml」 「csv」 「stream」 「parser」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 denis-kisel/stream-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 denis-kisel/stream-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 denis-kisel/stream-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Load DOM document safety
laravel facade to read/write csv file
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-26