jorisros/data-compare

能够比较大数据集的组件

v1.0.4 2019-10-16 23:53 UTC

This package is auto-updated.

Last update: 2024-09-15 20:15:28 UTC


README

Build Status Maintainability

DataCompare 组件

这是一个组件,可以帮助你检测两个数组之间是否有变化。

要求

此组件从 PHP 7.0 到 7.3 都兼容。

示例

$product = Product::getBySku($xmlProduct['sku']);

if (!$product) {
    $product = new Product();
}

$dataproviderA = new \DataCompare\SimpleProvider();
$dataproviderA->addString('sku', $product->getSku());
$dataproviderA->addString('title', $product->getTitle());
$dataproviderA->addString('price', $product->getPrice());

$dataproviderB = new \DataCompare\SimpleProvider(); 
$dataproviderB->addString('sku', $jsonImport->sku);
$dataproviderB->addString('title', $jsonImport->title);
$dataproviderB->addString('price', $jsonImport->price);

$compareComponent = new \DataCompare\DataCompare($dataproviderA, $dataproviderB);

if (!$compareComponent->isTheSame()){
    // If result is not equal update the product
    $product->save()
}

待办事项

  • 检查数组的结构是否相同
  • 返回存在问题的数据集