hgato/php-crud-comparator 问题修复 & 功能扩展

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

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

hgato/php-crud-comparator

最新稳定版本:v1.0.5

Composer 安装命令:

composer require hgato/php-crud-comparator

包简介

Library to compare PHP model arrays

README 文档

README

This library is meant to compare arrays of models and return 3 arrays: to create, to update, to delete.

Logic of execution is following:

  • array of old models is provided as a first argument
  • array of new models is provided as a second argument
  • array of id fields is provided as the third argument
  • array of secondary fields is provided as fourth argument
  • if the model with same ids (all id fields treated as combined key) exists in both old and new array but secondary fields are different - model is treated as one for update
  • if the model with same ids exists in both old and new array and secondary fields are same - model is ignored
  • if model is in old array but not in new - model is meant to be deleted
  • im model vice versa in noe, but not in old - model is meant for creation

Typical use case: frontend sends an array of models, but doesn't say what have changed. Simultaneously some data is in database already. This library helps to fund difference.

Example

class TestObject
{
  public $id;
  public $key;
  public $name;
  public $description;
}

$oldArray = [/* Some instances of TestObject*/];
$newArray = [/* Other instances of TestObject*/];

$comparator = new ObjectComparator();
$comparator->compare(
    $oldArray,
    $newArray,
    ['id', 'key'],
    ['name', 'description']
);

$create = $comparator->getCreate();
$update = $comparator->getUpdate();
$delete = $comparator->getDelete();

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固