chemaclass / edifact-parser
An EDIFACT file parser to extract the values from any defined segment
Fund package maintenance!
www.paypal.me/chemaclass
Installs: 2 638
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 5
Forks: 3
Open Issues: 3
Requires
- php: >=8.0
- ext-json: *
- sabas/edifact: ^0.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.12
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.4
- vimeo/psalm: ^4.29
This package is auto-updated.
Last update: 2024-12-06 20:53:49 UTC
README
EDIFACT stands for Electronic Data Interchange For Administration, Commerce, and Transport
.
This repository contains a parser for any EDIFACT file to extract the values from any segment defined in an EDIFACT formatted file.
Ok, but... What is EDIFACT?
Format of an EDIFACT file
-
Each line of the file consists of a set of data that belongs to a specific segment of a message.
-
A segment is defined by a tag. Following the rest of the data that belongs to that segment. More about segments here.
-
A message is a list of segments. Usually, all segments between the UNH and UNT segments compound a message.
-
A transaction is the list of messages that belongs to a file.
Installation
composer require chemaclass/edifact-parser
Contribute
You are more than welcome to contribute reporting issues, sharing ideas, or contributing with your Pull Requests.
Basic examples
You can see a full example of printing segments.
You can see a full example of extracting data.
<?php declare(strict_types=1); use EdifactParser\EdifactParser; use EdifactParser\Segments\NADNameAddress; require dirname(__DIR__) . '/vendor/autoload.php'; $fileContent = <<<EDI UNA:+.? ' UNB+UNOC:3+9457386:30+73130012:30+19101:118+8+MPM 2.19+1424' UNH+1+IFTMIN:S:93A:UN:PN001' TDT+20' NAD+CZ+0410106314:160:Z12++Company Centre+c/o Carrier AB+City1++12345+DE' NAD+CN+++Person Name+Street Nr 2+City2++12345+DE' UNT+18+1' UNZ+2+8' EDI; $parserResult = EdifactParser::createWithDefaultSegments()->parse($fileContent); $firstMessage = $parserResult->transactionMessages()[0]; $cnNadSegment = $firstMessage->segmentByTagAndSubId('NAD', 'CN'); $personName = $cnNadSegment->rawValues()[4]; var_dump($personName); // 'Person Name'