gupalo/item-syncer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 truth
  • localItems: 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 anything
    • syncArchiving: if local item has method archive then archive local item
    • syncRemoving: 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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2023-01-08