PHPackages                             kaliop/csv-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. kaliop/csv-parser

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

kaliop/csv-parser
=================

PHP/OOP CSV Parser

v1.0.0(6y ago)0391MITPHP

Since May 27Pushed 6y ago5 watchersCompare

[ Source](https://github.com/kaliop/csv-parser)[ Packagist](https://packagist.org/packages/kaliop/csv-parser)[ Docs](https://tech.kaliop.com)[ RSS](/packages/kaliop-csv-parser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

CSV Parser Library
==================

[](#csv-parser-library)

This library allows you to define your CSV parsing in OOP style, allowing you to easily filter and test your imports. It's been in production on various large clients with multiples complex imports for quite some time now.

Main advantages are:

- OOP-style: One *Parser* class per import = meaningful for developers working on the project.
- Testable: A fixture csv and you can easily write tests for the import.
- Fully Customizable: each parsed result is also a PHP class where the developer can add its own logic.
- Lightly coupled: this package depends only on Symfony's Validator. Any database/persistence stuff is possible (see example below).

Installation
------------

[](#installation)

Install this package using composer:

```
composer require kaliop/csv-parser
```

Basic Usage
-----------

[](#basic-usage)

You'll need to describe the mapping between CSV columns and entity's properties. To do so, you should start by creating a *Parser*, but first, let's take a look at our CSV:

```
date;order_id;client_name;address;postal_code;country;amount
2019-04-15;678945;"Laurent Doe";"12 avenue PhpUnit";34000;France;12
2019-03-12;987564;"Ruh Doe";"15 rue du test";31001;France;50,53
2019-05-01;123456;"Julien Doe";"125 rue PHP";34440;France;69,12
2019-02-09;456123;"Gérard Doe";"15 blvd Bouchard";76000;France;789,10
2019-01-01;965478;"Jean-Luc Doe";"15 rue du test";34000;France;5,00
2019-05-01;126578;"Bernard Doe";"15 rue Symfony";75000;France;33,53
2019-05-01;216543;"Maël Doe";"Disneyland Paris";77000;France;1250,53
2019-05-01;987521;"Gros Doe";"15 rue de Behat";98520;France;50,98
```

our Entity looks like this:

```
