edifact
Tools to process EDI messages in UN/EDIFACT format, (*1)
Supported syntax is version 3., (*2)
It's provided in a Composer package:, (*3)
composer require sabas/edifact
, (*4)
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
, (*5)
EDI/Parser
Given an edi message checks the syntax, outputs errors and returns the message as a multidimensional array., (*6)
INPUT, (*7)
$c = new Parser($x);
Where $x
could be:
* a url
* a string (wrapped message)
* an array of strings (a segment per entry), (*8)
OR, (*9)
```php
$c = new Parser();
$c->load($file);
$c->loadString($string);, (*10)
**OUTPUT**
Errors
```php
$c->errors();
Array, (*11)
$c->get();
EDI/Encoder
Given a multidimensional array (formatted as the output of the parser), returns an EDI string, optionally one segment per line., (*12)
INPUT, (*13)
$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), (*14)
$wrap
is a boolean, if you need a segment per line. Set to false to disable wrapping, (*15)
OR, (*16)
$c = new Encoder();
$c->encode($array, $wrap);
OUTPUT, (*17)
$c->get(); // returns String
EDI/Analyser
Create from EDI file readable structured text with comments from segments.xml
., (*18)
INPUT, (*19)
$analyser = new EDI\Analyser();
$analyser->loadSegmentsXml('edifact/src/EDI/Mapping/d95b/segments.xml');
-
$url
is the path to orginal EDI message file
-
$parsed
is a by EDI\Parser()
created EDI messages array
TEXT OUTPUT, (*20)
$analyser->process($parsed); // returns text
Or, (*21)
$analyser->process($parsed, $rawSegments);
-
$rawSegments
(optional) is segments in raw format from EDI\Parser::getRawSegments
to be printed before each segment in the analysed result
JSON OUTPUT
Get a json representation of the array, with the element names as key., (*22)
$analyser->process($parsed);
$json = $analyser->getJson();
EDI/Reader
Read from EDI file requested segment element values., (*23)
INPUT, (*24)
$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), (*25)
OR, (*26)
$c = new Parser($x);
$r=new Reader();
$r->setParsedFile($c);
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPpreperation();
OUTPUT
Errors, (*27)
$c->errors();
Array, (*28)
$c->get();
EDI/Interpreter
Organizes the data parsed by EDI/Parser using the xml description of the message and the xml segments., (*29)
INPUT, (*30)
$p=new EDI\Parser($edifile);
$edi = $p->get();
$analyser = new EDI\Analyser();
$segs =$analyser->loadSegmentsXml('vendor/sabas/edifact-data/D95B/segments.xml');
$interpreter = new EDI\Interpreter('vendor/sabas/edifact-data/D95B/messages/codeco.xml', $segs);
$prep = $interpreter->prepare($edi);
OUTPUT, (*31)
Json, (*32)
$interpreter->getJson()
Errors (per message), (*33)
$interpreter->getErrors()
Example
Edifact, (*34)
DTM+7:201309200717:203'
, (*35)
Array, (*36)
['DTM',['7','201309200717','203']]
Syntax data
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/., (*37)
Notes
Valid characters are: A-Za-z0-9.,-()/'+:=?!"%&*;<> UNECE, (*38)