gupalo/item-syncer
最新稳定版本:1.3.0
Composer 安装命令:
composer require gupalo/item-syncer
包简介
Item Syncer
关键字:
README 文档
README
Sync remote to local items.
Install
composer require gupalo/item-syncer
How to use
Create 2 arrays with items implementing \Gupalo\ItemSyncer\SyncableEntityInterface:
remoteItems: usually from external API - source of truthlocalItems: items from your DB
Update logic:
- remote item that is missing locally - create
- remote item that exists locally - update (you implement logic which properties should be updated)
- local item that is missing remotely - you decide by selecting sync method:
syncKeeping: don't do anythingsyncArchiving: if local item has methodarchivethen archive local itemsyncRemoving: remove local items
If you use Doctrine and save diff to database then use DbItemSyncer. If you have your own logic of processing diff
then use ItemSyncer and its diffKeeping, diffArchiving, diffRemoving methods.
Example
$remoteItems = array_map( static fn(array $a) => Country::createFromApi($a), $this->countryApiClient->getCountries() ); $localItems = $this->countryRepository->findAll(); $diff = $this->dbItemSyncer->syncArchiving($remoteItems, $localItems); print_r($diff->stat()); // something like ['created' => 2, 'updated' => 180]
统计信息
- 总下载量: 4.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2023-01-08