babeuloula/collection-diff
最新稳定版本:1.0.3
Composer 安装命令:
composer require babeuloula/collection-diff
包简介
Collection Diff allows you to compare 2 data collections to find operations to do: CREATE, UPDATE or DELETE data.
README 文档
README
Collection Diff allows you to compare 2 data collections to find operations to do: CREATE, UPDATE or DELETE data.
Requirements
- PHP ^7.1
Installation
composer install babeuloula/collection-diff
Usage
If you want to compare data between database and form (like $_POST)
<?php // Collection from your database $from = [ new FooObject("foo", "category1", 10.5), new FooObject("bar2", "category2", 9.5), new FooObject("bar1", "category1", 9.5), new FooObject("barFoo", "category1", 9.5), new FooObject("barFooBar", "category1", 9.5), ]; // Collection from you form like $_POST $to = [ [ "name" => "foo", "category" => "category1", "price" => 11.5 ], [ "name" => "bar2", "category" => "category2", "price" => 9.5, ], [ "name" => "bar1", "category" => "category2", "price" => 9.5, ], [ "name" => "fooBar", "category" => "category3", "price" => 8.5, ], ];
You need to call CollectionDiff::compare to execute the comparison then call CollectionDiff::getActions to retrieve
actions.
CollectionDiff::compare first parameter is an array of primary keys needed by Collection Diff to execute the
comparison to check the concordance on this keys.
Your object will be normalized to be compared.
See example above.
Symfony
If you want to use Collection Diff in your Symfony project, you can use the bridge
Wizaplace\CollectionDiff\Bridge\CollectionDiffBundle.
$container ->get(\Wizaplace\CollectionDiff\CollectionDiff::class) ->compare(['name', 'category'], $from, $to, false, true) ->getActions();
Standalone
$mySerializer = new FooSerializer(); $collectionDiff = new Wizaplace\CollectionDiff\CollectionDiff($mySerializer); $collectionDiff->compare(['name', 'category'], $from, $to, false, true); $collectionDiff->getActions(); // Or $collectionDiff->getNothing(); $collectionDiff->getCreate(); $collectionDiff->getUpdate(); $collectionDiff->getDelete();
Return the following results
array (size=4)
1 =>
array (size=1)
0 =>
array (size=3)
'name' => string 'bar2' (length=4)
'category' => string 'category2' (length=9)
'price' => float 9.5
2 =>
array (size=1)
0 =>
array (size=3)
'name' => string 'fooBar' (length=6)
'category' => string 'category3' (length=9)
'price' => float 8.5
3 =>
array (size=2)
0 =>
array (size=3)
'name' => string 'foo' (length=3)
'category' => string 'category1' (length=9)
'price' => float 11.5
1 =>
array (size=3)
'name' => string 'bar1' (length=4)
'category' => string 'category2' (length=9)
'price' => float 9.5
4 =>
array (size=1)
0 =>
array (size=3)
'name' => string 'barFoo' (length=6)
'category' => string 'category1' (length=9)
'price' => float 9.5
babeuloula/collection-diff 适用场景与选型建议
babeuloula/collection-diff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 babeuloula/collection-diff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 babeuloula/collection-diff 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-27