flow-php/etl-adapter-csv

PHP ETL - Adapter - CSV

1.x-dev 2021-10-11 08:13 UTC

This package is auto-updated.

Last update: 2021-10-11 08:13:58 UTC


README

Minimum PHP Version

Description

ETL Adapter that provides Loaders and Extractors that works with CSV files.

Following implementation are available:

Extractor - LeagueCSVExtractor

<?php

use Flow\ETL\Adapter\CSV\LeagueCSVExtractor;
use Flow\ETL\Row;
use Flow\ETL\Rows;
use League\Csv\Reader;

$reader = Reader::createFromPath(__DIR__ . '/../Fixtures/annual-enterprise-survey-2019-financial-year-provisional-csv.csv');
$reader->setHeaderOffset(0);

$extractor = new LeagueCSVExtractor($reader, 5);

/** @var Rows $rows */
foreach ($extractor->extract() as $rows) {
    // Do something with Row 
}

Loader - LeagueCSVLoader

<?php

use Flow\ETL\Adapter\CSV\LeagueCSVLoader;
use Flow\ETL\Row;
use Flow\ETL\Rows;
use League\Csv\Writer;

$path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_csv_loader', true) . '.csv';
$writer = Writer::createFromPath($path, 'w+');

$loader = new LeagueCSVLoader($writer);

$loader->load(new Rows(
    Row::create(new Row\Entry\ArrayEntry('row', ['id', 'name'])),
    Row::create(new Row\Entry\ArrayEntry('row', [1, 'Norbert'])),
));
$loader->load(new Rows(
    Row::create(new Row\Entry\ArrayEntry('row', [2, 'Tomek'])),
    Row::create(new Row\Entry\ArrayEntry('row', [3, 'Dawid'])),
));

Development

In order to install dependencies please, launch following commands:

composer install

Run Tests

In order to execute full test suite, please launch following command:

composer build

It's recommended to use pcov for code coverage however you can also use xdebug by setting XDEBUG_MODE=coverage env variable.