CSV Bundle
![Build Status][travis-image]
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., (*1)
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:, (*2)
$ composer require kuborgh/csv-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*3)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Kuborgh\CsvBundle\KuborghCsvBundle(),
);
// ...
}
// ...
}
Configuration
Following configuration variables exist an can be inserted into the config.yml of your project, (*4)
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
Usage
To parse CSV you simply call, (*5)
$parser = $container->get('kuborgh_csv.parser.<my_parser>');
$array = $parser->parse($csv);
To generate CSV you simply call, (*6)
$generator = $container->get('kuborgh_csv.generator.<my_generator>');
$csv = $generator->generate($array);
Testing
The whole parser should be unittested. You can run the tests with, (*7)
$ composer install
$ bin/phpunit
The coverage report is saved in the coverage folder and should always cover 100%, (*8)