tomcan/feed-importer
Composer 安装命令:
composer require tomcan/feed-importer
包简介
Package to download and parse csv product feeds
README 文档
README
Because everybody loves importing csv files...
Why?
Importing data from csv feeds can be hard. Often you'll end up with a custom implementation, closely coupling the downloading, reading, processing of the data. Each of them comes with their own difficulties and complexity. Is it on disk, http or a SSL authenticated ftp? Do you even have enough memory or diskspace available to download and extract that 2GB large gzipped, 12GB unzipped products.csv.gz?
The result is often a mess of control code mixed in with your business logic. And then you need to do the same but differently for another feed, and you end up duplicating half of your code and rewriting the rest. I have been there too! And I was feed up with it (pun intended).
What
What if I told you that you now can just define the feed, write your logic to process a single record and be done?
Tom's Feed Importer abstracts all the feed handling parts away and just gives you the records one by one, so that you can process them in small, sizeable parts.
You can either use a foreach / generator approach, or a callback function. Whichever suits your needs the best.
With foreach / generator
// define the feed
$feed = new FeedDefinition(['url' => 'https://raw.githubusercontent.com/TomCan/feed-importer/refs/heads/main/samples/toms-favorite-names.csv']);
// instantiate processor without callback
$processor = new FeedProcessorCsv($feed);
// instantiate downloader
$downloader = new FeedDownloader($feed, $processor);
// use ->generate function
foreach ($downloader->generate() as $row) {
echo 'Got a record: '.str_replace(PHP_EOL, ' ', print_r($row, true)).PHP_EOL;
}
// profit
With callback function
// define the feed
$feed = new FeedDefinition(['url' => 'https://raw.githubusercontent.com/TomCan/feed-importer/refs/heads/main/samples/toms-favorite-names.csv']);
// write your callback
$callback = function (array $row) {
echo 'Got a record: '.str_replace(PHP_EOL, ' ', print_r($row, true)).PHP_EOL;
};
// instantiate processor with callback
$processor = new FeedProcessorCsv($feed, $callback);
// instantiate downloader
$downloader = new FeedDownloader($feed, $processor);
// use ->download function
$downloader->download();
// profit
It mostly comes down to defining your feed parameters with a FeedDefinition. See the options page in the docs for a
reference of the available options.
tomcan/feed-importer 适用场景与选型建议
tomcan/feed-importer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tomcan/feed-importer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomcan/feed-importer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2024-11-22