Symfony bundle for handling CSV files.

Installs: 190

Dependents: 0

Watchers: 8

Forks: 1

Language: PHP

v0.0.3 2014-03-21 18:53 UTC


This is a bundle used for the reading, validation, and parsing of TSV & CSV files developed internally at The Nerdery.

Installation (via Composer)

Drop the following into your project's composer.json require block:

"nerdery/csv-bundle": "v0.0.3"

Basic Usage

$readerOptions = array(
     CsvFileReaderOptions::OPTION_VALIDATION => $this->csvFileValidator,
     CsvFileReaderOptions::OPTION_PARSER     => $this->csvFileParser,

$csvFileReaderOptions = new CsvFileReaderOptions($readerOptions);

$reader =  new CsvFileReader(

$dataRows = $reader->parse(PATH_TO_FILE);

//Do some stuff with the data



This class handles configuring the file reader for usage, setting things like delimiter, adding parsing/validation, etc.

Full options list:
  • CsvFileReaderOptions::OPTION_LENGTH

    Used to specify the length of the longest line in the CSV file. Defaults to 0, meaning no maximum is imposed.

  • CsvFileReaderOptions::OPTION_DELIMITER

    The character to be used for denoting the end of a column and beginning of the next. Defaults to \t (tab character).

  • CsvFileReaderOptions::OPTION_ENCLOSURE

    The character that will be used for denoting a piece of text. Defaults to " (double quote).

  • CsvFileReaderOptions::OPTION_ESCAPE The character used to escape reserved/special characters. Defaults to \ (backslash).
  • CsvFileReaderOptions::OPTION_HEADER_POLICY

    The policy to designate how the header is going to be handled. Defaults to CsvFileReaderOptions::HEADER_POLICY_SUB_DATA_OPTIONAL

    • CsvFileReaderOptions::HEADER_POLICY_NO_HEADER

      Signifies that no header is present in the file being parsed

    • CsvFileReaderOptions::HEADER_POLICY_DISREGARD

      Signifies that a header is present, but should not be processed.


      Process file with header. Signifies that the number of data columns may outnumber the number of header columns. Useful for variable column count files.


      Process file with header. Signifies that the number of data columns in any given row may not exceed the number of columns in the header row.

  • CsvFileReaderOptions::OPTION_USE_LABELS_AS_KEYS

    Whether or not to use header row labels as the keys for the array of row data. Defaults to true.

  • CsvFileReaderOptions::OPTION_VALIDATION

    An implementation of the AbstractCsvFileRowValidator to use for validating the file. null by default.

  • CsvFileReaderOptions::OPTION_PARSER

    An implementation of the AbstractCsvFileRowParser to use for parsing the file. null by default.


The main operating class for the library. Handles running through the file, pushing it in to an associative array (as well as calling any added parsing/validation). Takes CsvFileReaderOptions and an instance of a class implementing EventDispatcherInterface.


Guidelines on usage to come. In the meantime, please see the class documentation.


Guidelines on usage to come. In the meantime, please see the class documentation.