Download the PHP package chemaclass/edifact-parser without Composer

On this page you can find all versions of the php package chemaclass/edifact-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package edifact-parser

πŸ“¦ EDIFACT Parser

Scrutinizer Code Quality Type Coverage CI PHP Version

A complete PHP toolkit for UN/EDIFACT β€” read, write, validate, and stream EDI interchanges with a typed, object-oriented API.

EDIFACT β€” Electronic Data Interchange For Administration, Commerce, and Transport β€” is the international standard for structured business documents (orders, invoices, despatch advices, transport instructions). πŸ” New to it? Start here.

Why this library

Table of Contents

For AI coding agents: docs/llms/. Every snippet there is backed by a runnable file under example/ that CI executes.


πŸ’Ύ Installation

Requires PHP 8.0+ with ext-json and ext-mbstring.


πŸš€ Quick Start

The parser never throws on unknown segments β€” they become UnknownSegments you can still read via rawValues(), so you can process any interchange and add typed segments later.


πŸ“₯ Parsing

EdifactParser::parse() / parseFile() return a ParserResult:

A message starts at UNH and ends at UNT; an interchange wraps messages between UNB and UNZ, optionally grouped by UNG/UNE. Invalid input throws InvalidFile.

Choosing a tokenizer

Turning raw text into segments is pluggable. NativeTokenizer is the default β€” a regex-free single-pass scanner, ~1.8Γ— faster at tokenizing (~1.3Γ— on parse() overall), and it never rewrites the bytes it reads:

SabasTokenizer delegates to sabas/edifact, which was the default up to 6.x. It is still available, but be aware it strips every byte in \x80-\xFF β€” NAD+BY+++MΓΌller comes back as Mller:

Reach for it when you need bug-for-bug compatibility with 6.x, or want the restricted UNOB repertoire enforced. Otherwise the default is both faster and lossless.

For ASCII input the two tokenize identically β€” verified segment-for-segment across the test fixtures and a generated corpus.


Streaming large files

Stream messages one at a time in bounded memory β€” ideal for large interchanges. A leading UNA service-string advice (custom separators/release char) is honoured automatically:


πŸ–₯️ Command line

composer require installs an edifact binary. It answers "what is in this file?" without writing a script β€” and it is built for automation as much as for people:

Contract, so output can be consumed without guessing:

No console framework is pulled in β€” a parsing library should not put one in your vendor/.


πŸ“– Reading data

Typed accessors

Typed segments expose their fields as methods β€” self-documenting and IDE-friendly:

Every segment also exposes the raw structure when you need it:

Accessing segments

Dumping a message

toArray() / toJson() render a whole message β€” or a single segment β€” as plain data, with context children nested. Useful for logs, snapshot tests and diffing interchanges:

Fluent query API

Chain filters and transformations over every segment (order preserved, duplicates included):

query() and $message->segments() return every segment in original order, duplicates included. The keyed lookups (segmentByTagAndSubId(), allSegments()) index by tag + subId and keep the last occurrence β€” use the query API when duplicates matter.

Line items

Line items group each LIN with its related detail segments (QTY, PRI, PIA, …) β€” ideal for orders and invoices:

Hierarchical context segments

Context segments preserve parent β†’ child relationships (e.g. NAD β†’ CTA β†’ COM):

Keyed lookups always hand back the typed segment, so you can go the other way too β€” read a segment normally, then ask the message what was grouped under it:

Interchange & envelope metadata

Every envelope segment exposes typed metadata:

Functional groups (UNG/UNE)

When an interchange wraps messages in UNG…UNE groups, read them directly. Interchanges without groups return an empty list β€” messages stay available flat via transactionMessages():

Statistics & analysis

MessageAnalyzer extracts counts and aggregates:

Qualifier constants

Avoid magic strings with typed qualifier catalogs (IDE autocomplete, usable in match):

Class Covers
NADQualifier Party roles β€” BY, SU, CN, CZ, DP, IV, PR, CA, FW, MF, UC, WH
QTYQualifier Quantity types β€” 1, 3, 11, 12, 21, 33, 46, 47, 48, 192
PRIQualifier Price types β€” AAA, AAB, AAE, AAF, AAG, CAL, CT, DIS, LIS, MIN, RRP
DTMQualifier Date/time types β€” 137, 2, 3, 4, 10, 11, 13, …
RFFQualifier Reference types β€” ON, IV, DQ, CU, SRN, CT, POR, …

Character sets

The parser reads raw bytes. Decode non-ASCII values to UTF-8 from the interchange's syntax identifier:

UNOA/UNOB β†’ ASCII, UNOC–UNOK β†’ ISO-8859-*, UNOY β†’ UTF-8.

Built-in segments

32 segments are typed and registered by default (134 with SegmentFactory::withDirectorySegments()):

Any other tag parses as an UnknownSegment (readable via rawValues()); add your own typed class in a few lines β€” see Extending.


πŸ“€ Writing EDIFACT

Build individual segments

Fluent, type-safe builders produce segment objects:

NADNameAddress, QTYQuantity and PRIPrice provide ::builder().

Serialize segments to a string

EdifactSerializer is the inverse of parsing β€” it round-trips a parsed interchange byte-for-byte and escapes separators/release chars for you:

Assemble a full interchange

InterchangeBuilder writes a complete UNB…UNZ interchange and fills in the UNT segment counts and the UNZ control count automatically:


βœ… Validation

Check a message against a pluggable rule set β€” required segments, cardinality, and relative order. The validator never throws; an empty result means the message conforms:

Ready-made rule sets for common message types are provided as starting points:


πŸ”§ Extending

Custom segments

Extend AbstractSegment and register your class. The shared accessor helpers (element(), component(), firstComponent()) safely read simple and composite elements:

withAdditionalSegments() keeps every default and merges your tags on top β€” registering a custom class under a default tag overrides that default. Use withSegments() instead when you want an explicit, closed set of segments.

Introspection

Ask the factory what it knows, instead of reading the source:

Descriptors are derived by reflection, so they cannot drift from the code. registeredTags() and classForTag() read the map only β€” no class is loaded.

The shape of toArray()/toJson() is published as a JSON Schema at schema/message.schema.json, and a test asserts the schema still matches what a parsed message actually produces.

Composable segment bundles

The defaults are exposed as two composable bundles so you can build a lean factory that only types the tags you care about β€” everything else still parses as a readable UnknownSegment:

Custom grouping rules

Context hierarchies and line-item boundaries are driven by GroupingRules. Pass a customized instance to change which tags open a context, attach as children, or close a line-item section:

GroupingRules also reads back what it is configured with β€” contextTags(), childTags(), breakLineItemTags() β€” and the defaults are exposed as GroupingRules::DEFAULT_CONTEXT_TAGS, DEFAULT_CHILD_TAGS and DEFAULT_BREAK_LINE_ITEM_TAGS.

More examples in extracting data, query filtering, printing segments, context segments.


πŸ› Debugging

Error handling

Structured diagnostics

Matching on English prose is fragile, so parse failures and validation failures share one type with stable codes and, where known, a position:

Codes are public API β€” see DiagnosticCode for the catalogue. Messages are not: they may be reworded at any time.


πŸ› οΈ Development

CI runs the benchmarks on every pull request, measuring the base branch and the head branch on the same runner and failing when a metric regresses beyond 1.5Γ—. Absolute timings on shared hardware mean little; ratios measured back to back do. Never change tools/benchmark.php in a commit that also reports a performance delta β€” the numbers stop being comparable.

Local toolchain note: the pinned Psalm (vimeo/psalm ^4.30) runs on PHP ≀ 8.3 β€” run it under 8.3 if your CLI is newer. On PHP > 8.3, PHP-CS-Fixer needs PHP_CS_FIXER_IGNORE_ENV=1.


🀝 Contributing

Contributions of all kinds are welcome β€” bug fixes, ideas, and improvements.

πŸ“‹ See the contributing guide to get started.


All versions of edifact-parser with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
ext-mbstring Version *
php Version >=8.0
sabas/edifact Version ^1.3
webmozart/assert Version ^1.12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package chemaclass/edifact-parser contains the following files

Loading the files please wait ...