PHPackages                             madewithlove/export - 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. madewithlove/export

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

madewithlove/export
===================

Interfaces and basic implementations for file exports from a web application

1.1.0(9y ago)41.9k[1 issues](https://github.com/madewithlove/export/issues)MITPHPPHP &gt;=5.5.0

Since Feb 22Pushed 9y ago1 watchersCompare

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

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

Export interface with a CSV implementation
==========================================

[](#export-interface-with-a-csv-implementation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/10e960d6ac242b38fb12c660b57447308211ccbf6ac34f2babb111185b1dbcc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616465776974686c6f76652f6578706f72742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/madewithlove/export)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/965daf091cdbaea969ce97352df1759ba1adec5a9e791fc8617cde203cc92634/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d616465776974686c6f76652f6578706f72742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/madewithlove/export)[![Code Coverage](https://camo.githubusercontent.com/33f8fb5b945c84a50cffa3ecec69ba2de516a076ca11d28ec05bd2cde6e40c32/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d616465776974686c6f76652f6578706f72742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/madewithlove/export)[![Quality Score](https://camo.githubusercontent.com/4ad78309e200e594bcfcdcb3eef77b9ffdfbe72e1f128eaa43bbdb91a1950a9f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d616465776974686c6f76652f6578706f72742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/madewithlove/export)

Usage
-----

[](#usage)

What it does in one code sample:

```
// A list of users to export.
$users = [
    [
        'username' => 'John Doe',
        'email' => 'john.doe@gmail.com',
    ],
    [
        'username' => 'Jane Doe',
        'email' => 'jane.doe@gmail.com',
    ],
];

// Create a new CSV exporter object.
$exporter = new Madewithlove\Export\Csv\Exporter();

// Create a new custom Transformer object (an anonymous class, only in PHP 7)
$transformer = new class implements Madewithlove\Export\Csv\Transformer, Madewithlove\Export\Csv\WithHeaders {
    public function getHeaders()
    {
        return ['username', 'email'];
    }

    public function transform(array $user)
    {
        return [
            $user['username'],
            $user['email'],
        ];
    }
};

$exporter->setItems($users);
$exporter->setTransformer($transformer);

// New controller being (an anonymous class, only in PHP 7)
$controller = new class {
    use Madewithlove\Export\Http\Psr7Response;

    /**
     * @param Madewithlove\Export\Exporter $exporter
     */
    public function index(Exporter $exporter)
    {
         return $this->fileDownload($exporter->getContent(), 'users.csv');
    }
};

$psrResponse = $controller->index($exporter);
```

### CSV exporter

[](#csv-exporter)

The included CSV exporter (`Madewithlove\Export\Csv\Exporter`) will create the file contents for a CSV export file. For that it uses the Writer class of the `league/csv` package, but that's just an implementation detail. It adheres to the `Madewithlove\Export\Exporter` interface (feel free to make an XML or any other exporter implementation) and returns the file content when you call the `getContent()` method on it. You can define which items it should export by passing an array or an `Iterator` (like a [`Generator`](http://php.net/manual/en/language.generators.overview.php)) to the `setItems($items)` method. You can also optionally set a Transformer to apply a transformation on each row of the given items. This `Transformer` is used by the `League\Csv\Writer` class, and may implement the `Madewithlove\Export\Csv\WithHeaders` contract to let the writer know which headers the CSV file should have.

### Transformers

[](#transformers)

A Transformer object has a method `transform(array $row) : array` which allows you to do transformations on each row. The interface `Madewithlove\Export\Csv\WithHeaders` defines a `getHeaders() : array` method that returns the headers to be used in the CSV file.

This package also includes some transformer implementations for general usage:

#### Callable transformer

[](#callable-transformer)

This allows you to use any callable (function) without having to create a class that implements the Transformer interface. Create one by using the factory method, or use the setter method:

```
use Madewithlove\Export\Csv\Transformers\CallableTransformer;

$transformer = (new CallableTransformer())->setTransformer(function (array $row) {...});

$transformer = CallableTransformer::fromCallable(function (array $row) {...});
```

#### Null transformer, just headers

[](#null-transformer-just-headers)

When you don't really need to do a transformation on the row, but you do want to insert headers in the CSV file, use the `JustHeaders` transformer class:

```
use Madewithlove\Export\Csv\Transformers\JustHeaders;

$transformer = (new JustHeaders())->setHeaders(['username', 'email']);

$transformer = JustHeaders::fromHeaders(['username', 'email']);
```

#### Headers decorator

[](#headers-decorator)

When you have an existing Transformers object but you want it to add headers to the CSV file too, you don't need to extend it. Just wrap it with the `WithHeadersDecorator` like this:

```
use Madewithlove\Export\Csv\Transformers\JustHeaders;

$transformer = new WithHeadersDecorator($reusedTransformer, $headers);

$transformer = (new WithHeadersDecorator($reusedTransformer))->setHeaders($headers);
```

### HTTP Response objects

[](#http-response-objects)

Both Symfony and PSR-7 reponse objects are supported. Use the trait `Madewithlove\Export\Http\SymfonyResponse` or `Madewithlove\Export\Http\Psr7Response` in your controller to make a file download response object with the `fileDownload($content, $filename)` method. This requires you to install the `symfony/http-foundation` package or `zendframework/zend-diactoros` package respectively.

Install
-------

[](#install)

In order to install it via composer you should run this command:

```
composer require madewithlove/export
```

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Credits
-------

[](#credits)

[All Contributors](https://github.com/madewithlove/export/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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 ~134 days

Total

2

Last Release

3601d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/df052a58ecfa5a07fd2b4cb12bb128ab28ff4b8e82fb0831eab81623b898ddb4?d=identicon)[madewithlove-machine-user](/maintainers/madewithlove-machine-user)

![](https://www.gravatar.com/avatar/9937cd6d2eff58e99c75bc2d4a53066e7c9cfdec457c798d5d02d37e6947f419?d=identicon)[hannesvdvreken](/maintainers/hannesvdvreken)

---

Top Contributors

[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (22 commits)")

---

Tags

responseexportcsvdownloadreusableextendable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/madewithlove-export/health.svg)

```
[![Health](https://phpackages.com/badges/madewithlove-export/health.svg)](https://phpackages.com/packages/madewithlove-export)
```

###  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)[goodby/csv

CSV import/export library

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

Lightweight Exporter library

44920.9M35](/packages/sonata-project-exporter)[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1623.1M35](/packages/kartik-v-yii2-export)[handcraftedinthealps/goodby-csv

CSV import/export library

441.6M4](/packages/handcraftedinthealps-goodby-csv)

PHPackages © 2026

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