Download the PHP package proengeno/edifact without Composer
On this page you can find all versions of the php package proengeno/edifact. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download proengeno/edifact
More information about proengeno/edifact
Files in proengeno/edifact
Package edifact
Short Description Parse, build, serialize and validate UN/EDIFACT messages
License MIT
Informations about the package edifact
PHP - EDIFACT
Parse, build, serialize and validate UN/EDIFACT messages in a memory efficient way.
Installation
Version 2.0 requires PHP 8.4+. If you are on PHP 8.1–8.3, use the 1.x releases (composer require apfelfrisch/edifact:^1.3).
See the CHANGELOG for what is new in 2.0, including the breaking changes when upgrading from 1.x.
You will likely have to generate your own Segments, see php-edifact/edifact-mapping for XML mappings. I have done a prototype for autogeneration, it should give you a good starting point.
If you don't need validation or segment getters you can also parse to the GenericSegment.
Usage
Parse EDIFACT Messages
Load Segment Classes
You can add your Segments to the factory like so:
After that you can either mark the factory as default:
or use the factory directly:
If you don't need validation or segment getters you can also parse to the GenericSegment:
Parse from String
Parse from File
Iterate over Segments
Filter Segments
Unwrap Messages
Splits an interchange into one message per UNH...UNT block (the segment names are configurable).
The partial messages above live in memory. If you need every partial as its own Stream (e.g. to keep the
raw segment lines, the file handle or to build your own wrapper around it), unwrap the stream instead and hand
each partial to the factory. A leading UNA segment is copied into every partial, escaped segment terminators
stay escaped.
fromStream() uses the given stream as is; the factory's read filters are only applied to streams it opens
itself via fromString() / fromFilepath().
Add Readfilter
Build a Message
Build with default Una
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
If you replace the decimal separator, be sure that the blueprint marks the value as numeric.
Write directly into File
Add Writefilter to the Builder
Validate a complete Interchange (CONTRL-style syntax check)
The InterchangeValidator checks the structure of a whole transmission file
(UNB/UNZ and UNH/UNT service segments, matching references, control counts,
duplicate message references) plus the blueprints of all registered segments,
following the CONTRL check order: an interchange level failure stops the
check, a failing message reports only its UNH/UNT failures while other
messages are still checked.
Every SyntaxFailure carries the UN/EDIFACT error code (service code
list 0085) and the context needed to fill the UCI/UCM/UCS/UCD segments of a
CONTRL message: the affected service segment, the message counter and
reference, the segment position within the message and the element/component
positions.
Checks that need knowledge the file itself cannot provide (own MP-ID,
known senders, already received interchange references, message type
descriptions) remain the concern of the application; SyntaxErrorCode
provides the matching codes (7, 23, 25, 26, 35, 36, …) for reporting them.
Validate Message Segments
Development
The project uses Mago for formatting, linting and static analysis, and PHPUnit for tests: