code-pilots/change-set-collection
Composer 安装命令:
composer require code-pilots/change-set-collection
包简介
The utility is designed to detect the state of change set relative to two iterables list
关键字:
README 文档
README
The utility is designed to detect the state of change set relative to two iterables list
Installation
Install the latest version with
$ composer require code-pilots/change-set-collection
Basic Usage
Example 1:
$changeSet = new ChangeSetCollection( collection1: [ new User(id: 1, name: 'User 1'), new User(id: 5, name: 'User 5'), new User(id: 7, name: 'User 7'), ], collection2: [ new User(id: 1, name: 'EditedUser 1'), new User(id: 10, name: 'NewUser 10'), ], getId: fn (User $user) => $user->getId(), ); echo $line = '--------' . PHP_EOL; foreach ($changeSet as $change) { if ($change->isAdd()) { echo '+' . $change->element2->getName() . PHP_EOL; echo $line; } elseif ($change->isEdit()) { echo '-' . $change->element1->getName() . PHP_EOL; echo '+' . $change->element2->getName() . PHP_EOL; echo $line; } elseif ($change->isRemove()) { echo '-' . $change->element1->getName() . PHP_EOL; echo $line; } }
Output:
--------
-User 1
+EditedUser 1
--------
+NewUser 10
--------
-User 5
--------
-User 7
--------
Example 2:
// Create and compare change set $changeSet = new ChangeSetCollection( collection1: [ new Order(id: Uuid::from('00000000-0000-0000-0000-000000000001'), customer: 'Jon'), new Order(id: Uuid::from('00000000-0000-0000-0000-000000000002'), customer: 'Doe'), ], collection2: [ ['uuid' => '00000000-0000-0000-0000-000000000001', 'customer' => 'Dan'], ['uuid' => null, 'customer' => 'Wendy'], ], getId: fn (User|array $order) => $order instanceof Order ? $order->getId() : $order['uuid'], ); // Example helper function $_separator = '--------' . PHP_EOL; $_writeOutputBlock = static function(string ...$lines) { foreach ($lines as $line) { echo $line . PHP_EOL; } echo $_separator; } echo $_separator; foreach ($changeSet as $change) { match ($change->state) { ChangeState::add => $_writeOutputBlock( '+' . $change->element2['customer'], ), ChangeState::edit => $_writeOutputBlock( '-' . $change->element1->getCustomer(), '+' . $change->element2['customer'], ), ChangeState::remove => $_writeOutputBlock( '-' . $change->element1->getCustomer(), ), } } echo PHP_EOL . sprintf( '[Added: %d], [Edited: %d], [Removed: %d]', $changeSet->countAdded(), $changeSet->countEdited(), $changeSet->countRemoved(), );
Output:
--------
-Jon
+Dan
--------
-Doe
--------
+Wendy
--------
[Added: 1], [Edited: 1], [Removed: 1]
For contributors
Run tests
Exec: ./vendor/bin/phpunit
Run lint
Exec phpstan: ./vendor/bin/phpstan analyse src tests
Exec psalm: ./vendor/bin/psalm
code-pilots/change-set-collection 适用场景与选型建议
code-pilots/change-set-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.03k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「collection」 「change-set」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 code-pilots/change-set-collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 code-pilots/change-set-collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 code-pilots/change-set-collection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package provides type-safe extension of the laravel collection, forcing a single type of object.
Traits to build collections of specific objects
ItalyStrap Helpers
Froq! Collection.
Model and Collection classes
A simple collection library for PHP.
统计信息
- 总下载量: 2.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-18