PHPackages                             zumba/csv-policy - 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. zumba/csv-policy

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

zumba/csv-policy
================

Simple, policy-driven csv rules validation

v0.2.0(12y ago)86841[1 issues](https://github.com/zumba/csv-policy/issues)MITPHPPHP &gt;=5.4

Since Jan 2Pushed 12y ago6 watchersCompare

[ Source](https://github.com/zumba/csv-policy)[ Packagist](https://packagist.org/packages/zumba/csv-policy)[ Docs](http://engineering.zumba.com)[ RSS](/packages/zumba-csv-policy/feed)WikiDiscussions master Synced 3d ago

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

CsvPolicy
=========

[](#csvpolicy)

[![Build Status](https://camo.githubusercontent.com/91c66c1e7488fb10c9198033757ce1fde66c8a8fedc3a9cfeeaf662dd648dc1c/68747470733a2f2f7472617669732d63692e6f72672f7a756d62612f6373762d706f6c6963792e706e67)](https://travis-ci.org/zumba/csv-policy)

**CsvPolicy** is a simple, policy-based validation library for CSV files. Create rules for columns in a CSV file and the validator will load them, parse the file, and report rule violations.

*CsvPolicy requires PHP &gt;= 5.4*

Example
-------

[](#example)

Suppose you have the following business requirements for a CSV file named `products.csv` that will be uploaded to your application:

1. It must contain the following column names: `id`, `value`
2. It must contain at least one of the following columns: `upc`, `code`, `stock`
3. The `id` column's values must be unique.
4. The `value` column must only contain numeric values

CsvPolicy allows you to model these rules as classes. Required and optional fields are handled by the `Validator` class directly, so we only need to define rules for the `id` column and the `value` column.

CsvPolicy uses Traits for common validation operations (e.g. checking all values in a column are unique). The folowing rule will ensure that the values in the `id` field are unique:

```
namespace Zumba\CsvPolicy\Rule\Products;

use \Zumba\CsvPolicy\Behavior;

class Id extends \Zumba\CsvPolicy\Rule {

	use Unique;

	public function getErrorMessage($input) {
		return 'Id must be unique.  Duplicate found: ' . $input;
	}
}
```

You can override the `Rule::validationLogic` method to define custom validation for that column. The validator will use this method to check all of the values in the CSV for the column.

```
namespace Zumba\CsvPolicy\Rule\Products;

class Value extends \Zumba\CsvPolicy\Rule {
	public function getErrorMessage($input) {
		return 'Value must only contain numeric values. Non-numeric value found: ' . $input;
	}
	public function validationLogic($input) {
		return is_numeric($input);
	}
}
```

Finally, you configure your validator and use it to check if the CSV file is valid:

```
$validator = new \Zumba\CsvPolicy\Validator();
$validator->config([
	'rulesPath' => './path/to/custom/rules'
	'requiredFields' => [

		// string field names are always required
		'id', 'value',

		// arrays of field names indicate that at least one field is required, but not all
		['upc', 'code', 'stock']
	]
]);

$valid = $validator->isValid('./path/to/products.csv');
if (!$valid){
	// errors is an array of rules violations
	$errors = $validator->getErrors();
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.3% 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

Unknown

Total

1

Last Release

4515d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/26548?v=4)[Juan Basso](/maintainers/jrbasso)[@jrbasso](https://github.com/jrbasso)

![](https://avatars.githubusercontent.com/u/157755?v=4)[Chris Saylor](/maintainers/cjsaylor)[@cjsaylor](https://github.com/cjsaylor)

![](https://avatars.githubusercontent.com/u/497048?v=4)[Stephen Young](/maintainers/young-steveo)[@young-steveo](https://github.com/young-steveo)

---

Top Contributors

[![young-steveo](https://avatars.githubusercontent.com/u/497048?v=4)](https://github.com/young-steveo "young-steveo (55 commits)")[![cjsaylor](https://avatars.githubusercontent.com/u/157755?v=4)](https://github.com/cjsaylor "cjsaylor (4 commits)")[![jrbasso](https://avatars.githubusercontent.com/u/26548?v=4)](https://github.com/jrbasso "jrbasso (4 commits)")

---

Tags

validatorcsvPolicycsv-policy

### Embed Badge

![Health badge](/badges/zumba-csv-policy/health.svg)

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[goodby/csv

CSV import/export library

9555.6M23](/packages/goodby-csv)[sonata-project/exporter

Lightweight Exporter library

44920.9M35](/packages/sonata-project-exporter)

PHPackages © 2026

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