PHPackages                             dmt-software/import-reader - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. dmt-software/import-reader

ActiveLibrary[File &amp; Storage](/categories/file-storage)

dmt-software/import-reader
==========================

Read parts of a file/stream into a series of objects or arrays

2.2.0(6mo ago)185[2 issues](https://github.com/dmt-software/import-reader/issues)1MITPHPPHP &gt;=7.4

Since Sep 27Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/dmt-software/import-reader)[ Packagist](https://packagist.org/packages/dmt-software/import-reader)[ RSS](/packages/dmt-software-import-reader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (24)Used By (1)

Import Reader
=============

[](#import-reader)

The reader is designed to go through a file to return chunks of its contents as objects without a high memory usage.

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

[](#installation)

`composer require dmt-software/import-reader`

Usage
-----

[](#usage)

### Create a reader

[](#create-a-reader)

The reader can be created manually or the [reader builder](docs/reader-builder.md) can be used to create a (default) reader or a pre-configured one.

```
use DMT\Import\Reader\Decorators\DecoratorInterface;
use DMT\Import\Reader\Decorators\Handler\GenericHandlerDecorator;
use DMT\Import\Reader\Handlers\JsonReaderHandler;
use DMT\Import\Reader\Reader;
use DMT\Import\Reader\Handlers\Sanitizers\SanitizerInterface;
use pcrov\JsonReader\JsonReader;

$internalReader = new JsonReader();
$internalReader->open('/path/to/some.json');

/** @var DecoratorInterface[] $decorators */
/** @var SanitizerInterface[] $sanitizers */
$reader = new Reader(
    new JsonReaderHandler($internalReader, ...$sanitizers),
    new GenericHandlerDecorator(),
    ...$decorators
);
```

Visit the [reader handler](docs/reader-handler.md) documentation for more information on the handlers internal readers and [sanitizers](docs/output-control.md#sanitizers).

### Adding decorators

[](#adding-decorators)

Once a default reader is created, it is possible to add extra decorators to apply on each object that is returned by the read method.

```
use DMT\Import\Reader\Decorators\ToObjectDecorator;
use DMT\Import\Reader\Reader;

/** @var Reader $reader */
$reader->addDecorator(new ToObjectDecorator(Customer::class, ['id' => 'id', 'name' => 'fullName', ]));

foreach ($reader->read() as $customer) {
    // import customer;
}
```

More on decorators see the [documentation](docs/output-control.md#decorators).

### Adding filters

[](#adding-filters)

Besides controlling the output by using a decorator a part of the object stream the reader returns can be skipped or filtered.

```
use DMT\Import\Reader\Reader;

/** start on item 4 */
$skip = 3;
/** skip all objects that has no id */
$filter = function (object $current) {
    return isset($current->id);
}

foreach ($reader->read($skip, $filter) as $item) {
    // import item
}
```

Visit the [filters section](docs/output-control.md#filters) for more information about filter callbacks.

Error Handling
--------------

[](#error-handling)

### UnreadableException

[](#unreadableexception)

This is thrown when the given file can not be read. This can have several causes:

- file is unreadable
- can not set file pointer
- end of file reached whilst set file pointer
- file pointer is set to the wrong return type

```
use DMT\Import\Reader\Exceptions\UnreadableException;

try {
    $readerBuilder->build($file, $options = []);
} catch (UnreadableException $exception) {
    // file can not be processed
}
```

### ReaderReadException

[](#readerreadexception)

This can happen when a single chunk can not be read from the file. It will stop execution of the reading process.

```
use DMT\Import\Reader\Exceptions\ReaderReadException;

try {
    foreach ($reader->read() as $n => $object) {
        // import object
    }
} catch (ReaderReadException $exception) {
    // execution stopped, after $n rows
}
```

### DecoratorException

[](#decoratorexception)

This exception happens silently. It triggers a user warning and continues the reading process. Depending on you server configuration this warning is ignored or send to STDOUT or STDERR.

### Other Exceptions or Errors

[](#other-exceptions-or-errors)

Any other kind of failures are (most likely) problems that are caused by configuration faults or when this software is implemented incorrect.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance49

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

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

Recently: every ~63 days

Total

23

Last Release

180d ago

Major Versions

v1.4.0 → v2.0.02023-02-20

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

2.2.x-devPHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec6b7fbb4d231b5c2c76348cf3a13ec5e82c64a1826142f6ec0db1cf15db2873?d=identicon)[proggeler](/maintainers/proggeler)

![](https://www.gravatar.com/avatar/ea1df8d4eb476756f31e2c698e8b2c161c8be1b8482091f930abbddfd8d2fc52?d=identicon)[lingonl](/maintainers/lingonl)

---

Top Contributors

[![proggeler](https://avatars.githubusercontent.com/u/18281353?v=4)](https://github.com/proggeler "proggeler (81 commits)")

---

Tags

streamjsonxmlcsvfilereaderiteratorimport

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dmt-software-import-reader/health.svg)

```
[![Health](https://phpackages.com/badges/dmt-software-import-reader/health.svg)](https://phpackages.com/packages/dmt-software-import-reader)
```

###  Alternatives

[rodenastyle/stream-parser

PHP Multiformat Streaming Parser

443195.7k2](/packages/rodenastyle-stream-parser)[adlawson/vfs

Virtual file system

300433.0k21](/packages/adlawson-vfs)[selective/rar

RAR file reader

2111.1k1](/packages/selective-rar)

PHPackages © 2026

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