PHPackages                             kubinyete/edi-php - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. kubinyete/edi-php

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

kubinyete/edi-php
=================

A standard library for reading EDI files and declaring your own EDI parsers

1.0.9(2y ago)1722MITPHP

Since Oct 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Kubinyete/edi-php)[ Packagist](https://packagist.org/packages/kubinyete/edi-php)[ RSS](/packages/kubinyete-edi-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (10)Used By (2)

EDI PHP
=======

[](#edi-php)

A standard library for declaring EDI parsers, because that's not a fun thing to do.

### Why should I use it?

[](#why-should-i-use-it)

This is a very common use-case for many services that output data using a defined text-file layout, for example, many services (Ex: Payment providers) output some sort of layout file that follows a simplified column separated values that has a fixed size set.

For example, the following line (25 bytes):

`120240503Hello World     `

Can be interpreted as

RangeSizeColumnValue0 - 01Reg. type11 - 88Date2024-05-039 - 2516MessageHello World### How it works

[](#how-it-works)

To provide a better developer experience while creating these parsers, this library provides some useful property attributes and a base class for declaring these types of data.

For example, to declare the previous line, we can declare it in code as the following:

```
final class ExampleLayoutType extends Registry {
    #[Number(1)]
    public int $type;

    #[Date(8, format: '!Ymd')]
    public DateTimeInterface $type;

    #[Text(16)]
    public string $message;
}

// We can parse the data directly
$example = ExampleLayoutType::from('120240503Hello World     ')

// Or we can hydrate it
$example = new ExampleLayoutType();
$example->hydrate('120240503Hello World     ');
```

### Declaring dynamic parsers

[](#declaring-dynamic-parsers)

Using our built in line parser, we can create dynamically parsed (by line) types, with the power of generators, these types are parsed on demand:

```
// Using a standard line parser, iterates over each line
class EDIParser extends LineParser
{
    // Ran on each line iteration
    protected function parse(LineContext $ctx): ?Registry
    {
        [$contents, $number] = $ctx->unwrap();
        // For this EDI file, we can deduce which type it is based on
        // the first 2 letters provided each line.
        $code = substr($contents, 0, 2);

        try {
            return match ($code) {
                EDIRegistry::TYPE_HEADER_START => EDIHeader::from($contents),
                EDIRegistry::TYPE_TRANSACTION_BATCH_START => EDITransactionBatch::from($contents),
                EDIRegistry::TYPE_SALE_RECEIPT => EDISaleReceipt::from($contents),
                // Our LineContext can provide a more verbose message to inform
                // where in our data the error ocurred.
                default => $ctx->raise("Cannot parse EDI of type '$code'", 0),
            };
        } catch (FieldException $e) {
            $ctx->raise($e->getMessage(), $e->getCursor());
        }
    }
}

// Using our parser directly
// Reading directly from stdin
$buffer = Stream::file('php://stdin', 'rb');
$parser = EDIParser::loadFromStream($buffer);

foreach ($parser as $registry) {
    /** @var Registry $registry */
    // We have direct access to our parsed objects on demand
    dump($registry);
}
```

### Understanding parsing errors

[](#understanding-parsing-errors)

> This feature is work-in-progress, there are a some things we can do to make it better

We enable out-of-the-box support for friendly contextual messages on any errors that ocurred.

```
PHP Fatal error:  Uncaught Kubinyete\Edi\Parser\Exception\ParseException: Line 1: Failed to parse field '202d1001025840' as a date with format 'YmdHis'
Contents: "A00003.1202d1001025840000442ADIQ SOLUCOES PAGAMENTOS S.A  0040002783189N000001"
           --------^
 in /home/vitorkubinyete/code/edi-php/src/Parser/LineContext.php:38
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

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

Recently: every ~51 days

Total

9

Last Release

743d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d9da6d81de7ebab59b0b9bda2a84521bc2300856c72c896bc63bd800ed099dd?d=identicon)[vitorkubinyete](/maintainers/vitorkubinyete)

---

Top Contributors

[![Kubinyete](https://avatars.githubusercontent.com/u/23388918?v=4)](https://github.com/Kubinyete "Kubinyete (18 commits)")

---

Tags

edilibraryparsingphpphp8

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kubinyete-edi-php/health.svg)

```
[![Health](https://phpackages.com/badges/kubinyete-edi-php/health.svg)](https://phpackages.com/packages/kubinyete-edi-php)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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