kionik/caesar
Composer 安装命令:
composer require kionik/caesar
包简介
Asynchronous string, file and xml readers based on ReactPHP
README 文档
README
Caesar is a library based on ReactPHP technology that provides to read strings and files in an asynchronous way and find matches in them by patterns.
Basic usage
$loop = \React\EventLoop\Factory::create(); $reader = new \Kionik\Caesar\Reader($loop); $reader->onFind('/foo/', function (string $foo) { echo $foo; // return 'foo' }); $reader->onEnd(function() { echo PHP_EOL . 'finish reading'; }); $reader->read('foo bar'); // some code... // This can be replaced by $loop->run(); $reader->run();
Reader working only with a strings, parse it and return result of parsing if found something.
FileReader
FileReader working only with a resources. Inside of read method use React\Stream\ReadableResourceStream of ReactPHP library that provides to read file in asynchronous stream way.
$fileName = 'foo.txt'; file_put_contents($fileName, 'foo bar'); $loop = \React\EventLoop\Factory::create(); $reader = new \Kionik\Caesar\FileReader($loop); $reader->onFind('/foo/', function (string $foo) { echo $foo; // return 'foo' }); $reader->read(fopen($fileName, 'rb')); // some code... $reader->run(); unlink($fileName);
You can change size of one chunk by using second parameter $chunkSize of read method
$chunkSize = 1; $reader->read(fopen('foo.txt', 'rb'), $chunkSize);
If you change chunk size then don't forget to change Parser::$storeChunksCount by using
$reader->setStoreChunksCount(10);
This parameter is responsible for the maximum number of chunks that will stored in FileReader memory, if FileReader wouldn't find something in previous chunks.
XmlStringReader
$loop = \React\EventLoop\Factory::create(); $reader = new \Kionik\Caesar\XmlStringReader($loop); $reader->onFind('foo', function (string $foo) { echo $foo; // return '<foo>bar</foo>' }); $reader->read('<foo>bar</foo><bar>foo</bar>'); // some code... $reader->run();
XmlFileReader
$fileName = 'foo.xml'; $xmlWriter = new \XMLWriter(); $xmlWriter->openMemory(); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->writeElement('foo', 'bar'); $xmlWriter->writeElement('bar', 'foo'); file_put_contents($fileName, $xmlWriter->flush(), FILE_APPEND); $loop = \React\EventLoop\Factory::create(); $reader = new \Kionik\Caesar\XmlFileReader($loop); $reader->onFind('foo', function (string $foo) { echo $foo; // return '<foo>bar</foo>' }); $reader->read(fopen($fileName, 'rb')); // some code... $reader->run(); unlink($fileName);
Note: XML readers does not work correctly in cases where tags are repeated inside themselves like:
<foo><foo>bar</foo></foo>
Handlers
All readers provides to use handlers for handling data before it returns to $listener.
$loop = \React\EventLoop\Factory::create(); $reader = new \Kionik\Caesar\XmlStringReader($loop); $reader ->onFind('tag', function (SimpleXMLElement $tag) { echo $tag->attributes()->getName(); // return 'foo' }) ->handler(new \Kionik\Caesar\Handlers\Xml\SimpleXMLElementHandler()); $reader->read('<tag foo="bar"></tag>'); // some code... $reader->run();
Licensing
All of the code in this library is licensed under the MIT license as included in the LICENSE file.
kionik/caesar 适用场景与选型建议
kionik/caesar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「file」 「parser」 「async」 「string」 「fast」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kionik/caesar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kionik/caesar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kionik/caesar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Load DOM document safety
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
Laravel Media Popup to upload/view the files
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-15