bagf/column-extractor

There is no license information available for the latest version (0.0.1) of this package.
Maintainers

👁 bagf

Package info

github.com/bagf/column-extractor

pkg:composer/bagf/column-extractor

Statistics

Installs: 15

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2017-11-28 18:19 UTC

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Unknown License 65c2bc927ba921d620f0ffd81bbdda8bc6960688

This package is not auto-updated.

Last update: 2026-06-21 15:36:40 UTC


README

Classes that extract, rename, transform CSV data

Usage

composer require bagf/column-extractor

Example

use Goodby\CSV\Import\Standard\LexerConfig;
use Goodby\CSV\Import\Standard\Lexer as CSVLexer;
use Bagf\ColumnExtractor\Column;
use Bagf\ColumnExtractor\ColumnExtractor;

$interpreter = new ColumnExtractor([
 // Matches the column 'User Code' and maps it to 'code' key in the rows() sub arrays
 (new Column('User Code'))->rename('code'),
 // You can chain operations currently rename and transform are supported
 // transform() accepts a closure that gets the current $line and matched column $contents
 (new Column('Number'))->transform(function($line, $contents) {...})->rename('id'),
]);

$config = new LexerConfig();
$config->setDelimiter(($commaDelimiter?',':"\t"));
(new CSVLexer($config))->parse('file.csv', $interpreter);

print_r($interpreter->rows());
print_r($interpreter->errors());