mshumakov/decomposer

此包已被弃用且不再维护。未建议替换包。

将大量数据分割成受控片段。

v3.1 2020-06-10 19:49 UTC

This package is auto-updated.

Last update: 2021-03-11 06:31:22 UTC


README

start with why build Codacy Badge Codacy Badge

此包用于大数据分割。

安装

要安装,请使用以下命令下载包。

composer require mshumakov/decomposer

示例

使用包将数据分割成片段的基本示例。

<?php
declare(strict_types=1);

use MSdev\Helper\Decomposer;

require __DIR__ . '/../vendor/autoload.php';

$data = [
    [...],
    [...],
    [...],
];

$batchSize = 10; // Fragment size
$totalCount = count($data); // Total amount of data
$params = [
    'hello' => 'world'
];

/**
 * In the response, we return the passed parameters 
 * ($params) and a list of fragments (key - 'list').
 * 
 * p.s.: More information in the tests.
 */
$decomposer = new Decomposer();
$fragments = $decomposer->decompose(
    $batchSize, 
    $totalCount,
    $params
);