[![Build Status][travis-image]][travis-url] [travis-url]: https://travis-ci.org/kuborgh/csv-bundle [travis-image]: https://secure.travis-ci.org/kuborgh/csv-bundle.svg?branch=master
This bundle is intended to be simple, but rfc4180 conform csv parser and writer. It will be extended in the future to fit more and more needs of custom implementations.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require kuborgh/csv-bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Kuborgh\CsvBundle\KuborghCsvBundle(),
);
// ...
}
// ...
}
Following configuration variables exist an can be inserted into the config.yml of your project
kuborgh_csv:
parser:
# Add here as many parser as you need. Each will get it's own service kuborgh_csv.parser.my_parser
my_parser:
# Delimiter (default: ",")
delimiter: ","
# Line Ending (default: "\r\n")
line_ending: "\r\n"
# Implementation for the parser. Possible values are "character" (default) oder "simple" (not recommended).
# You can add your own parser implementation by registering the class name in parameters like
# kuborgh_csv.parser.<my_implementation>.class
implementation: character
generator:
# Add here as many generators as you need. Each will get it's own service kuborgh_csv.generator.my_generator
my_generator:
# Delimiter (default: ",")
delimiter: ","
# Line Ending (default: "\r\n")
line_ending: "\r\n"
# Implementation for the generator. Possible values are "string" (default) oder "php" (not recommended).
# You can add your own generatr implementation by registering the class name in parameters like
# kuborgh_csv.generator.<my_implementation>.class
implementation: string
To parse CSV you simply call
$parser = $container->get('kuborgh_csv.parser.<my_parser>');
$array = $parser->parse($csv);
To generate CSV you simply call
$generator = $container->get('kuborgh_csv.generator.<my_generator>');
$csv = $generator->generate($array);
The whole parser should be unittested. You can run the tests with
$ composer install
$ bin/phpunit
The coverage report is saved in the coverage folder and should always cover 100%