jackal/copycat
Composer 安装命令:
composer require jackal/copycat
包简介
Library to copy `things` from one format to another
README 文档
README
A simple PHP to "copy" data from one source to another
Requirement
PHP >= 5.6
Getting Started
Install library with composer
composer require jackal/copycat
Usage
Basic example: from array to sql insert statement
require_once __DIR__.'/vendor/autoload.php';
$reader = new \Jackal\Copycat\Reader\ArrayReader([
['col1' => 'value1','col2' => 'value2'],
['col1' => 'value3','col2' => 'value4'],
/*...*/
]);
$workflow = new \Jackal\Copycat\Workflow($reader);
$workflow->addWriter(new \Jackal\Copycat\Writer\SQLFileWriter('test_table','test_table.sql'));
$workflow->process();
echo file_get_contents(__DIR__.'/test_table.sql');
From array to array
$reader = new \Jackal\Copycat\Reader\ArrayReader([
['value1'],
['value2'],
/*...*/
]);
$workflow = new \Jackal\Copycat\Workflow($reader);
$workflow->addWriter(new \Jackal\Copycat\Writer\ArrayWriter($outputArray));
$workflow->process();
var_dump($outputArray);
Filters
With Filters you can apply logic to exclude certain values from the output.
/*[...]*/
/*Define wich column to apply filter*/
$workflow->addFilter(new NotBlankFilter('col1'));
/*[...]*/
Filters are callable objects, you can define your own filter
/*[...]*/
/*Define custom filter*/
$workflow->addFilter(function($values){
return $values['col1'] > 0;
});
/*[...]*/
Converter
With Converter you can modify values to the output.
/*[...]*/
/*Define custom filter*/
$workflow->addConverter(new DatetimeToStringConverter('col1'));
/*[...]*/
You can set your own converter
/*[...]*/
//apply custom converter
$workflow->addConverter(function ($values){
foreach ($values as &$value) {
if ($value == 'to convert') {
$value = 'converted';
}
}
return $values;
});
/*[...]*/
Sorting
Is it possible to sort output values
/*[...]*/
//add sorter
$workflow->addSorter(new AscendingSorter('col1'));
/*[...]*/
If you want to sort values basing on multiple columns, you can just add multiple params. Use with care! this method could create performance issues on large input data
/*[...]*/
//add sorter
$workflow->addSorter(new AscendingSorter('col1','col2','col3',/*...*/));
/*[...]*/
Authors
- Luca Giacalone (AKA JackalOne)
License
This project is licensed under the MIT License
jackal/copycat 适用场景与选型建议
jackal/copycat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.35k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jackal/copycat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jackal/copycat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-14