PHPackages                             kunicmarko/importer - 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. kunicmarko/importer

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

kunicmarko/importer
===================

Importer that can handle different file types.

0.2.0(7y ago)410.3k↓80%11MITPHPPHP ^7.1

Since Jul 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kunicmarko20/importer)[ Packagist](https://packagist.org/packages/kunicmarko/importer)[ Docs](https://github.com/kunicmarko20/importer)[ RSS](/packages/kunicmarko-importer/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (7)Versions (4)Used By (1)

Importer
========

[](#importer)

Easier import from multiple file types (csv, json, xml, excel).

Support for Symfony, Lumen and Laravel.

[![PHP Version](https://camo.githubusercontent.com/2dcf2757d7a2ae7d144c6e7d9b63bd3383509e6b70bacccb3bd8ad04d1c2541c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312d626c75652e737667)](https://img.shields.io/badge/php-%5E7.1-blue.svg)[![Latest Stable Version](https://camo.githubusercontent.com/c113afd4dab581b46aefcd85203ffcee7a0159515bd77fa19089ff263d97ccc9/68747470733a2f2f706f7365722e707567782e6f72672f6b756e69636d61726b6f2f696d706f727465722f762f737461626c65)](https://packagist.org/packages/kunicmarko/importer)[![Latest Unstable Version](https://camo.githubusercontent.com/c83d67a7430b84596be08c97f5b626bee815e8c4c9b61a7307e4c994ccd34c35/68747470733a2f2f706f7365722e707567782e6f72672f6b756e69636d61726b6f2f696d706f727465722f762f756e737461626c65)](https://packagist.org/packages/kunicmarko/importer)

[![Build Status](https://camo.githubusercontent.com/ec402d871e1918c5e63bc0390fe1f47f1683b13b5ed54ab3c7e48a7d87c53ca4/68747470733a2f2f7472617669732d63692e6f72672f6b756e69636d61726b6f32302f696d706f727465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kunicmarko20/importer)[![Coverage Status](https://camo.githubusercontent.com/48eb7aae5ddb5eeb58a59252b6abc1e225e13674147dae11e15d3b8b4b9eae50/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b756e69636d61726b6f32302f696d706f727465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/kunicmarko20/importer?branch=master)

Documentation
-------------

[](#documentation)

- [Installation](#installation)
    - [Symfony](#symfony)
    - [Laravel](#laravel)
    - [Lumen](#lumen)
    - [Without Framework](#without-framework)
- [How to use](#how-to-use)
    - [ImportConfiguration](#importconfiguration)
        - [BeforeImport](#beforeimport)
        - [ChunkImport](#chunkimport)
    - [Import](#import)
        - [Import From File](#import-from-file)
        - [Import From String](#import-from-string)
    - [Pass Additional Data](#pass-additional-data)
- [Extending](#extending)

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

[](#installation)

**1.** Add dependency with composer

```
composer require kunicmarko/importer
```

### Symfony

[](#symfony)

Register the bundle in your `config/bundles.php`

```
return [
    //...
    KunicMarko\Importer\Bridge\Symfony\ImporterBundle::class => ['all' => true],
];
```

> By default, excel import is disabled, install "phpoffice/phpspreadsheet" to enable it.

### Laravel

[](#laravel)

Register the service provider in your `config/app.php`

```
providers' => [
    //...
    KunicMarko\Importer\Bridge\Laravel\ImporterServiceProvider::class,
],
```

> By default, excel import is disabled, install "phpoffice/phpspreadsheet" to enable it.

### Lumen

[](#lumen)

Register the service provider in your `bootstrap/app.php`

```
$app->register(KunicMarko\Importer\Bridge\Lumen\ImporterServiceProvider::class);
```

> By default, excel import is disabled, install "phpoffice/phpspreadsheet" to enable it.

### Without Framework

[](#without-framework)

Add the Readers you want to use to a Factory and get your Importer:

```
use KunicMarko\Importer\ImporterFactory;
use KunicMarko\Importer\Reader\CsvReader;
use KunicMarko\Importer\Reader\JsonReader;
use KunicMarko\Importer\Reader\XmlReader;
use KunicMarko\Importer\Reader\XlsxReader;

$importerFactory = new ImporterFactory();

$importerFactory->addReader(new CsvReader());
$importerFactory->addReader(new JsonReader());
$importerFactory->addReader(new XmlReader());
$importerFactory->addReader(new XlsxReader());

$importer = $importerFactory->getImporter('csv');
$importer->fromString('some,csv,string')
    ->useImportConfiguration(new YourImportConfiguration())
    ->import();
```

> If you want to use excel import, install "phpoffice/phpspreadsheet".

How to use
----------

[](#how-to-use)

### ImportConfiguration

[](#importconfiguration)

ImportConfiguration defines how should the data be mapped and saves the data. They have to implement `KunicMarko\Importer\ImportConfiguration` interface.

```
use KunicMarko\Importer\ImportConfiguration;

class ImportUserConfiguration implements ImportConfiguration
{
    public function map(array $item, array $additionalData)
    {
        $user = new User();

        $user->setUsername($item['username']);
        //..

        return $user;
    }

    public function save(array $items, array $additionalData): void
    {
        //save your users
    }
}
```

#### BeforeImport

[](#beforeimport)

BeforeImport allows your ImportConfiguration to do something with data before the mapping starts.

```
use KunicMarko\Importer\ImportConfiguration;
use KunicMarko\Importer\BeforeImport;
use Iterator;

class ImportSomethingConfiguration implements ImportConfiguration, BeforeImport
{
    public function before(Iterator $items, array $additionalData): Iterator
    {
        //start from 2nd line
        $items->next();

        return $items;
    }
}
```

#### ChunkImport

[](#chunkimport)

ChunkImport allows your configuration to define a number of items that the save method will receive, instead of receiving all at once.

```
use KunicMarko\Importer\ImportConfiguration;
use KunicMarko\Importer\ChunkImport;

class ImportChunkSomethingConfiguration implements ImportConfiguration, ChunkImport
{
    public function chunkSize(): int
    {
        return 50;
    }

    public function save(array $items, array $additionalData): void
    {
        //save will be called multiple times with 50 or less items
    }
}
```

### Import

[](#import)

After you have defined your import configuration, you can import from a file or from a string. You HAVE to provide one of those 2 options and your import configuration.

#### Import From File

[](#import-from-file)

```
use KunicMarko\Importer\ImporterFactory;

class UserImport
{
    private $importerFactory;

    public function __construct(ImporterFactory $importerFactory)
    {
        $this->importerFactory = $importerFactory;
    }

    public function import()
    {
        $importer = $importerFactory->getImporter('csv');

        $importer->fromFile('path/to/file.csv')
            ->useImportConfiguration(new YourImportConfiguration())
            ->import();
    }
}
```

#### Import From String

[](#import-from-string)

```
use KunicMarko\Importer\ImporterFactory;

class UserImport
{
    private $importerFactory;

    public function __construct(ImporterFactory $importerFactory)
    {
        $this->importerFactory = $importerFactory;
    }

    public function import()
    {
        $importer = $importerFactory->getImporter('csv');

        $importer->fromString('some,csv,string')
            ->useImportConfiguration(new YourImportConfiguration())
            ->import();
    }
}
```

> Excel import does not support import from a string.

### Pass Additional Data

[](#pass-additional-data)

Sometimes you may want to pass additional data to your import configuration.

```
use KunicMarko\Importer\ImporterFactory;

class UserImport
{
    private $importerFactory;

    public function __construct(ImporterFactory $importerFactory)
    {
        $this->importerFactory = $importerFactory;
    }

    public function import()
    {
        $importer = $importerFactory->getImporter('csv');

        $importer->fromString('some,csv,string')
            ->useImportConfiguration(new YourImportConfiguration())
            ->withAdditionalData(['user' => 'kunicmarko20'])
            ->import();
    }
}
```

Extending
---------

[](#extending)

You can always add your own custom readers, just implement `KunicMarko\Importer\Reader\Reader`interface and call `addReader()` method on ImporterFactory.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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

Total

2

Last Release

2903d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13528674?v=4)[Marko Kunic](/maintainers/kunicmarko20)[@kunicmarko20](https://github.com/kunicmarko20)

---

Top Contributors

[![kunicmarko20](https://avatars.githubusercontent.com/u/13528674?v=4)](https://github.com/kunicmarko20 "kunicmarko20 (9 commits)")

---

Tags

csvexcelhacktoberfestimportjsonlaravellumensymfonyxmljsonsymfonylaravelxmllumenexcelcsvimporter

### Embed Badge

![Health badge](/badges/kunicmarko-importer/health.svg)

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.9k157.3M893](/packages/maatwebsite-excel)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

578610.1k1](/packages/faisalman-simple-excel-php)[rodenastyle/stream-parser

PHP Multiformat Streaming Parser

447204.3k2](/packages/rodenastyle-stream-parser)[dracoblue/craur

A lossless xml to json and json to xml converter (and csv/xlsx/yaml). Writing PHP Json/Xml/Csv/Yaml/excel Importers made easy

4643.9k3](/packages/dracoblue-craur)[ee/dataexporter-bundle

Easy export data to CSV, XML, HTML, JSON or XLS

4982.9k](/packages/ee-dataexporter-bundle)

PHPackages © 2026

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