Extract / Transform / Load in PHP - Multiple formats - No dependency.

v2.5.1 2017-06-08 08:55 UTC

README

Latest Stable Version License Build Status Coverage Status Quality Score Total Downloads

This PHP 7.1+ library provides a very simple implementation of the Extract / Transform / Load pattern.

It is heavily inspired by the knplabs/etl library, with a more generic approach and less dependencies.

Overview

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

use BenTools\ETL\Event\ContextElementEvent;
use BenTools\ETL\Extractor\IncrementorExtractor;
use BenTools\ETL\Loader\DebugLoader;
use BenTools\ETL\Runner\ETLRunner;
use BenTools\ETL\Transformer\CallbackTransformer;

$items     = [
    'France',
    'Germany',
    'Poland',
];
$extract   = new IncrementorExtractor();
$transform = new CallbackTransformer('strtolower');
$load      = new DebugLoader();
$run       = new ETLRunner();

// Optionnal: hook on the AFTER_EXTRACT event to skip some elements
$run->onExtract(function (ContextElementEvent $event) {
    $element = $event->getElement();
    if ('Germany' === $element->getData()) {
        $element->skip();
    }
});

$run($items, $extract, $transform, $load);

Output:

array(2) {
  [0]=>
  string(6) "france"
  [2]=>
  string(7) "poland"
}

Installation

composer require  bentools/etl

Tests

./vendor/bin/phpunit

Documentation and recipes

Concept

Getting started

Extractors

Transformers

Loaders

Events

Advanced CSV to JSON conversion example

License

MIT