azphp/important

A library using an inverted generator to allow easy batching of data for a nice separation of logic

1.0.0 2019-06-29 21:46 UTC

This package is auto-updated.

Last update: 2024-11-25 06:10:24 UTC


README

Build Status

important

Simple library showing how to use an inverse generator to act as a batch importer

Configuration

composer require azphp/important

Usage

<?php

$batcher = function (array $values)
{
    /** @var \PDO $myDb */
    $stmt = $myDb->query('INSERT blah blah');
    // maybe do some data transformation
    $stmt->execute($values);
};

$importer = \AzPHP\Important\Importer::createImporter(
    $batcher,
    100
);

/** @var iterable $someData */
foreach ($someData as $value) {
    $importer->send($value);
}

// finish any extra values not covered by a batch
$importer->send(null);