PHPackages                             rdx/csv-mapper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rdx/csv-mapper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rdx/csv-mapper
==============

Extends league/csv with mappers and exceptions

1.2(6y ago)090MITPHP

Since Jun 26Pushed 6y agoCompare

[ Source](https://github.com/rudiedirkx/csv-mapper)[ Packagist](https://packagist.org/packages/rdx/csv-mapper)[ RSS](/packages/rdx-csv-mapper/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

CSV mapper
==========

[](#csv-mapper)

Uses `league\csv` for reading CSV. Adds record &amp; column mapping.

The first line is always used as header. You don't have to call `setHeaderOffset(0)`.

In all examples, `$reader` is iterated, not queried with a `Statement`:

```
foreach ( $reader as $record ) {
	// $record is done, no more processing needed
	print_r($record);
}

```

Record mappers
--------------

[](#record-mappers)

To keep only certain columns, and discard the rest, use the `KeepColumnsMapper`:

```
$reader = \rdx\csvmapper\Reader::createFromPath($file);
$reader->addMapper(new KeepColumnsMapper(['firstname', 'lastname', 'email']));

```

Create your own record mapper by implementing `RecordMapper`:

```
class AddTimestampMapper implements RecordMapper {
	protected $time;
	public function __construct( $time ) {
		$this->time = $time;
	}
	public function map( array $record, $index ) {
		$record['timestamp'] = $this->time;
		return $record;
	}
}

$reader->addMapper(new AddTimestampMapper(time()));

```

Require columns
---------------

[](#require-columns)

Require columns before processing iterating through the rows:

```
$reader = \rdx\csvmapper\Reader::createFromPath($file);
try {
	$reader->requireColumns(['email']);
}
catch ( MissingColumnsException $ex ) {
	echo implode(', ', $ex->getColumns());
}

```

Column mappers
--------------

[](#column-mappers)

If several columns in the same row have the same mapping, use the `ColumnsMapper` record mapper with the `ColumnMapper` interface.

To format several date fields with your own date formatter:

```
class DateFormatMapper implements ColumnMapper {
	public function map( array $record, $column, $index, $unset ) {
		$value = trim($record[$column]);
		$date = my_custom_date_maker($value);

		if ( !$date ) {
			// Invalid = NIL
			return null;

			// Invalid = skip field (remove from $record)
			return $unset;

			// Invalid = user error
			throw new LineException($index, "Invalid date: '$value'");
		}

		return $date;
	}
}

try {
	$reader = \rdx\csvmapper\Reader::createFromPath($file);
	$reader->addMapper(new ColumnsMapper(new DateFormatMapper(), ['birthdate', 'created_on', 'valid_until']));
}
catch ( LineException $ex ) {
	echo $ex->getMessage();
	print_r($ex->getRecord($reader));
}

```

This will run the `DateFormatMapper` max 3 times for every row. The mapper runs only for fields that exist in `$record`.

If you want to make a field from nothing, use `RecordMapper` to alter the record. `ColumnMapper` only alters/unsets columns.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~351 days

Total

3

Last Release

2225d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/78549c1dc5c83ec0201c9afc66762c6d5bbf770291b12bae5a7a65350f950dba?d=identicon)[rudiedirkx](/maintainers/rudiedirkx)

---

Top Contributors

[![rudiedirkx](https://avatars.githubusercontent.com/u/168024?v=4)](https://github.com/rudiedirkx "rudiedirkx (6 commits)")

### Embed Badge

![Health badge](/badges/rdx-csv-mapper/health.svg)

```
[![Health](https://phpackages.com/badges/rdx-csv-mapper/health.svg)](https://phpackages.com/packages/rdx-csv-mapper)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[statamic/cms

The Statamic CMS Core Package

4.8k3.6M965](/packages/statamic-cms)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k40](/packages/civicrm-civicrm-core)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

5.1k5.2k](/packages/shlinkio-shlink)[craftcms/feed-me

Import content from XML, RSS, CSV or JSON feeds into entries, categories, Craft Commerce products, and more.

293952.6k30](/packages/craftcms-feed-me)[oat-sa/tao-core

TAO core extension

66143.7k119](/packages/oat-sa-tao-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
