2017 © Pedro Peláez
 

library plum-csv

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

image

plumphp/plum-csv

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  • Wednesday, October 28, 2015
  • by florianeckerstorfer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 4,325 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Plum

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP., (*1)

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI, (*2)

Developed by Florian Eckerstorfer in Vienna, Europe., (*3)

Installation

You can install Plum using Composer., (*4)

$ composer require plumphp/plum-csv

Usage

Please refer to the Plum documentation for information about Plum in general., (*5)

Currently PlumCsv contains a reader and a writer for CSV files and uses League\CSV to actually read and write CSV files., (*6)

CsvReader

You can use the Plum\PlumCsv\CsvReader to read data from a .csv file., (*7)

use Plum\PlumCsv\CsvReader;

$reader = new CsvReader('countries.csv');

Optionally you can also pass the delimiter and enclosure to the constructor., (*8)

$reader = new CsvReader('countries.csv`, ',', '"');

Most CSV files have a header row. Because Plum processes a CSV file row by row you need to add HeaderConverter to change the index of each read item. In addition you can use the SkipFirstFilter to skip the header row. Both HeaderConverter and SkipFirstFilter are part of the core Plum package., (*9)

use Plum\Plum\Converter\HeaderConverter;
use Plum\Plum\Filter\SkipFirstFilter;

$workflow = new Workflow();
$workflow->addConverter(new HeaderConverter());
$workflow->addFilter(new SkipFirstFilter(1));
$reader = new CsvReader('countries.csv`, ',', '"');

CsvWriter

The Plum\PlumCsv\CsvWriter allows you to write the data into a .csv file., (*10)

use Plum\PlumCsv\CsvWriter;

$writer = new CsvWriter('foobar.csv', ',', '"');
$writer->prepare();
$writer->writeItem(['value 1', 'value 2', 'value 3');
$writer->finish();

The second and third argument of __construct() are optional and by default , and " respectively. In addition the setHeader() method can be used to define the names of the columns. It has to be called before the prepare()., (*11)

$writer = new CsvWriter('foobar.csv');
$writer->setHeader(['column 1', 'column 2', 'column 3']);
$writer->prepare();

When you read data dynamically you probably don't want to set the header columns manually. You can call autoDetectHeader() to use the array keys of the first item written to CsvWriter as headers., (*12)

$writer = new CsvWriter('foobar.csv');
$writer->autoDetectHeader(); // Must be called before the first `writeItem()`

If you need to further configure the writer, you can inject an instance of League\Csv\Writer to Plum\PlumCsv\CsvWriter., (*13)

use Plum\PlumCsv\CsvWriter;
use League\Csv\Writer;

$csv = Writer::createFromFileObject(new SplFileObject('countries.csv', 'w'));
$csv->setNullHandlingMode(Writer::NULL_AS_EMPTY);
$writer = new CsvWriter($csv);

Change Log

Version 0.4 (28 October 2015)

  • Check if item is array before auto-setting header
  • #10 Allow injection of League\Csv\Writer

Version 0.3.1 (28 April 2015)

  • Fix Plum version

Version 0.3 (22 April 2015)

  • Add support for ReaderFactory

Version 0.2 (21 April 2015)

  • Fix Plum version

Version 0.1 (24 March 2015)

  • Initial release

License

The MIT license applies to plumphp/plum.json. For the full copyright and license information, please view the LICENSE file distributed with this source code., (*14)

The Versions

28/10 2015

dev-master

9999999-dev

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/10 2015

0.4.x-dev

0.4.9999999.9999999-dev

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/10 2015

v0.4

0.4.0.0

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2015

0.3.x-dev

0.3.9999999.9999999-dev

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2015

v0.3.1

0.3.1.0

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/04 2015

v0.3

0.3.0.0

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

21/04 2015

0.2.x-dev

0.2.9999999.9999999-dev

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

21/04 2015

v0.2

0.2.0.0

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2015

0.1.x-dev

0.1.9999999.9999999-dev

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/03 2015

v0.1

0.1.0.0

PlumCsv includes CSV readers and writers for Plum. Plum is a data processing pipeline for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires