tomaj/csv-processor

CSV Processor

0.1.0 2015-05-15 09:06 UTC

This package is not auto-updated.

Last update: 2024-11-15 22:42:04 UTC


README

Kniznica pre procesovanie csvciek

Prudko v development mode - neoporucam pouzivat, zatial to je len vyextrahovane z projektu a nie su dobre zadefinovane zavyslosti

Build Status Code Climate Test Coverage Dependency Status

Latest Stable Version Total Downloads Latest Unstable Version License

Pouzitie

Kazdy import je zlozeny z 3 casti.

  1. Extractor - existuju 2 aktualne, pre csv a zip subory. Jeho ulohou je nacitat data zo vstupu
  2. Procesor - trieda do ktorej je potrebne nastavit jednotlive procesory na fieldy.
  3. Implementacia biznis logiky s datami ktore sa nacitali a spracovali.

Prakticky to moze vyzerat takto:

use Tomaj\CsvProcessor\CsvExtractor;
use Tomaj\CsvProcessor\DataProcessor;
use Tomaj\CsvProcessor\Converters\EncodingConverter;
use Tomaj\CsvProcessor\Processors\PassField;
use Tomaj\CsvProcessor\Processors\RemoveField;
use Tomaj\CsvProcessor\Line;

$csvExtractor = new CsvExtractor('cesta_k_suboru_.csv', ';');
$csvExtractor->addConverter(new EncodingConverter('WINDOWS-1250', 'UTF-8')); // mozme nastavit konverziu ak treba
$data = $csvExtractor->loadData();

$processor = new DataProcessor($output);
$processor->addProcessor(new PassField('field_name', 'name')); // field 'file_name' z csvcka sa do vystupu dostane ako field 'name'
$processor->addProcessor(new RemoveField('field_ktory_sa_zmaze'));
$processor->processData($data, function(Line $line, $pid)) {
	// tu je mozne naimlementovat logiku co sa ma stat s $line kde su spracovane data
});