PHPackages                             proengeno/edifact - 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. proengeno/edifact

Abandoned → [apfelfrisch/edifact](/?search=apfelfrisch%2Fedifact)Library[Parsing &amp; Serialization](/categories/parsing)

proengeno/edifact
=================

Parse, build, serialize and validate UN/EDIFACT messages

1.3.1(2y ago)1031.8k3[2 issues](https://github.com/Apfelfrisch/Edifact/issues)MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0CI failing

Since Jun 5Pushed 1y ago3 watchersCompare

[ Source](https://github.com/Apfelfrisch/Edifact)[ Packagist](https://packagist.org/packages/proengeno/edifact)[ RSS](/packages/proengeno-edifact/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (5)Versions (28)Used By (0)

PHP - EDIFACT
=============

[](#php---edifact)

[![Unit test](https://github.com/Apfelfrisch/Edifact/actions/workflows/phpunit.yml/badge.svg)](https://github.com/Apfelfrisch/Edifact/actions/workflows/phpunit.yml/badge.svg)[![Static Analysis](https://github.com/Apfelfrisch/Edifact/actions/workflows/phpstan.yml/badge.svg)](https://github.com/Apfelfrisch/Edifact/actions/workflows/phpstan.yml/badge.svg)[![Mutation tests](https://github.com/Apfelfrisch/Edifact/actions/workflows/infection.yml/badge.svg)](https://github.com/Apfelfrisch/Edifact/actions/workflows/infection.yml/badge.svg)

Parse, build, serialize and validate UN/EDIFACT Messages in a memory efficient way.

You will likely have to generate your own Segments, see [php-edifact/edifact-mapping](https://github.com/php-edifact/edifact-mapping) for XML Mappings. I have done a [protype](https://github.com/Apfelfrisch/ediseg-generator) for autogeneration, it should give you a good starting point.

If you don't need validation or Segment getter you can also parse to the generic Segment.

Usage
-----

[](#usage)

### Parse EDIFACT Messages

[](#parse-edifact-messages)

#### Load Segment Classes

[](#load-segment-classes)

You can add your Segments to the Factory like so:

```
use Apfelfrisch\Edifact\Segment\SegmentFactory;

$segmentFactory = new SegmentFactory;
$segmentFactory->addSegment('SEQ', \My\Namespace\Segments\Seq::class);
```

After that you can either mark the Factory as default:

```
$segmentFactory->markAsDefault();
```

or you inject the Factory in the Message:

```
use Apfelfrisch\Edifact\Segment\SegmentFactory;

$message = Message::fromString("UNA:+.? 'SEQ+1", $segmentFactory);
```

If you don't need validation or Segment getter you can also parse to the generic Segement

```
use Apfelfrisch\Edifact\Segments\Generic;
use Apfelfrisch\Edifact\Segment\SegmentFactory;

$segmentFactory = new SegmentFactory;
$segmentFactory->addFallback(Generic::class);
$segmentFactory->markAsDefault();
```

#### Parse from String

[](#parse-from-string)

```
use Apfelfrisch\Edifact\Message;

$message = Message::fromString("UNA:+.? 'NAD+DP++++Musterstr.::10+City++12345+DE");
```

#### Parse from File

[](#parse-from-file)

```
use Apfelfrisch\Edifact\Message;

$message = Message::fromFilepath('path/to/file.txt');
```

#### Iterate over Segments

[](#iterate-over-segments)

```
use Apfelfrisch\Edifact\Segments\SegmentInterface;

foreach ($message->getSegments() as $segment) {
    if ($segment instanceof SegmentInterface) {
        echo $segment->name();
    }
}
```

#### Filter Segments

[](#filter-segments)

```
use My\Namespace\Segments\MyNad;

foreach ($message->filterSegments(MyNad::class) as $segment) {
    echo $segment->name(); // NAD
}

$message->filterSegments(MyNad::class, fn(Nad $seg): bool
    => $seg->street() === 'Musterstr.'
);

echo $message->findFirstSegment(MyNad::class)->name(); // NAD
```

#### Unwrap Messages

[](#unwrap-messages)

```
foreach ($message->unwrap() as $partialMessage) {
    echo $segment instanceof \Apfelfrisch\Edifact\Message;
}
```

#### Add Readfilter

[](#add-readfilter)

```
$message->addStreamFilter('iso-to-utf8', 'convert.iconv.ISO-8859-1.UTF-8');
```

### Build a Message:

[](#build-a-message)

#### Build with default Una

[](#build-with-default-una)

```
use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Message;
use My\Namespace\Segments\MyUnb;
use My\Namespace\Segments\MyUnh;

$builder = new Builder;

$builder->writeSegments(
    MyUnb::fromAttributes('1', '2', 'sender', '500', 'receiver', '400', new DateTime('2021-01-01 12:01:01'), 'unb-ref'),
    MyUnh::fromAttributes('unh-ref', 'type', 'v-no', 'r-no', 'o-no', 'o-co')
);

$message = new Message($builder->get());
```

UNA and the trailing Segments (UNT and UNZ) will be added automatically. If no UNA Segment is provided, it uses the default values \[UNA:+.? '\].

#### Build with custom Una

[](#build-with-custom-una)

```
use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Segment\UnaSegment;

$builder = new Builder(new UnaSegment('|', '#', ',', '!', '_', '"'));
```

If you replace the decimal seperator, be sure that the blueprint marks the value as numeric.

#### Write directly into File

[](#write-directly-into-file)

```
use Apfelfrisch\Edifact\Builder;
use Apfelfrisch\Edifact\Segment\UnaSegment;

$builder = new Builder(new UnaSegment, 'path/to/file.txt');
```

#### Add Writefilter to the Builder

[](#add-writefilter-to-the-builder)

```
use Apfelfrisch\Edifact\Builder;

$builder = new Builder;
$builder->addStreamFilter('utf8-to-iso', 'convert.iconv.UTF-8.ISO-8859-1');
```

### Validate Message Segments

[](#validate-message-segments)

```
use Apfelfrisch\Edifact\Message;
use Apfelfrisch\Edifact\Validation\Failure;
use Apfelfrisch\Edifact\Validation\Validator;

$message = Message::fromString("UNA:+.? 'SEQ+9999", $segmentFactory);

$validator = new Validator;

if(! $validator->isValid($message)) {
    foreach ($validator->getFailures() as $failure) {
        echo $failure instanceof Failure;
    }
}
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99.1% 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 ~109 days

Recently: every ~134 days

Total

27

Last Release

840d ago

Major Versions

0.11.0 → 1.02022-03-18

PHP version history (7 changes)0.1.0PHP &gt;=5.4.0

0.1.1PHP &gt;=5.5.0

0.3.0PHP ^7.4|^8.0

0.4.0PHP ^8.0

1.1.0PHP ~8.0.0 || ~8.1.0

1.1.2PHP ~8.0.0 || ~8.1.0 || ~8.2.0

1.3.1PHP ~8.1.0 || ~8.2.0 || ~8.3.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4519207?v=4)[Apfelfrisch](/maintainers/Apfelfrisch)[@Apfelfrisch](https://github.com/Apfelfrisch)

---

Top Contributors

[![Apfelfrisch](https://avatars.githubusercontent.com/u/4519207?v=4)](https://github.com/Apfelfrisch "Apfelfrisch (313 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/proengeno-edifact/health.svg)

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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