Tools to process EDI messages in UN/EDIFACT format
Supported syntax is version 3.
It's provided in a Composer package:
composer require sabas/edifact
The mapping xml files are provided in a separate repository (https://github.com/sabas/edifact-data). To get them within the repository remember to clone with the --recursive flag, or download them with git submodule update --init --recursive
Given an edi message checks the syntax, outputs errors and returns the message as a multidimensional array.
INPUT
$c = new Parser($x);Where $x could be:
- a url
- a string (wrapped message)
- an array of strings (a segment per entry)
OR
$c = new Parser();
$c->load($file);
$c->loadString($string);OUTPUT
Errors
$c->errors();Array
$c->get();Given a multidimensional array (formatted as the output of the parser), returns an EDI string, optionally one segment per line.
INPUT
$c = new Encoder($x, $wrap = true);$x is a multidimensional array where first dimension is the EDI segment, second contains elements:
- single value
- array (representing composite elements)
$wrap is a boolean, if you need a segment per line. Set to false to disable wrapping
OR
$c = new Encoder();
$c->encode($array, $wrap);OUTPUT
$c->get(); // returns StringCreate from EDI file readable structured text with comments from segments.xml.
INPUT
$analyser = new EDI\Analyser();
$analyser->loadSegmentsXml('edifact/src/EDI/Mapping/d95b/segments.xml');$urlis the path to orginal EDI message file$parsedis a byEDI\Parser()created EDI messages array
TEXT OUTPUT
$analyser->process($parsed); // returns textOr
$analyser->process($parsed, $rawSegments);$rawSegments(optional) is segments in raw format fromEDI\Parser::getRawSegmentsto be printed before each segment in the analysed result
JSON OUTPUT Get a json representation of the array, with the element names as key.
$analyser->process($parsed);
$json = $analyser->getJson();Read from EDI file requested segment element values.
INPUT
$r = new Reader($x);
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPpreperation();Where X could be:
- a url
- a string (wrapped message)
- an array of strings (a segment per entry)
OR
$c = new Parser($x);
$r = new Reader();
$r->setParsedFile($c);
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPpreperation();OUTPUT Errors
$c->errors();Array
$c->get();Organizes the data parsed by EDI/Parser using the xml description of the message and the xml segments.
INPUT
$p = new EDI\Parser($edifile);
$edi = $p->get();
$analyser = new EDI\Analyser();
$segs = $analyser->loadSegmentsXml('vendor/sabas/edifact-data/D95B/segments.xml');
$svc = $analyser->loadSegmentsXml('vendor/sabas/edifact-data/Service_V3/segments.xml');
$interpreter = new EDI\Interpreter('vendor/sabas/edifact-data/D95B/messages/codeco.xml', $segs, $svc);
$prep = $interpreter->prepare($edi);OUTPUT
Json
$interpreter->getJson()Json for interchange service segments (UNB / UNZ)
$interpreter->getJsonServiceSegments()Errors (per message)
$interpreter->getErrors()Edifact
DTM+7:201309200717:203'
Array
['DTM',['7','201309200717','203']]Processed from EDI PEAR Package by David JEAN LOUIS (izi), downloadable from https://code.google.com/p/izi-sandbox/source/browse/trunk/php/php_edi/.
Valid characters are: A-Za-z0-9.,-()/'+:=?!"%&*;<> UNECE