tomaj / csv-processor
CSV Processor
Installs: 5 174
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >= 5.3.7
Requires (Dev)
- phpunit/phpunit: >4.2
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: ~2.0
This package is not auto-updated.
Last update: 2024-11-01 22:31:10 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
Pouzitie
Kazdy import je zlozeny z 3 casti.
- Extractor - existuju 2 aktualne, pre csv a zip subory. Jeho ulohou je nacitat data zo vstupu
- Procesor - trieda do ktorej je potrebne nastavit jednotlive procesory na fieldy.
- 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 });