Giter VIP home page Giter VIP logo

edifact's Introduction

edifact

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 package:

composer require php-edifact/edifact-mapping

EDI\Parser

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();

EDI\Encoder

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 String

EDI\Analyser

Create from EDI file readable structured text with comments from segments.xml. Requires the EDI\Mapping package.

INPUT

$mapping = new EDI\Mapping\MappingProvider('D95B');
$analyser = new EDI\Analyser();
$analyser->loadMessageXml($mapping->getMessage('CODECO'));
$analyser->loadSegmentsXml($mapping->getSegments());
  • $url is the path to orginal EDI message file
  • $parsed is an EDI message array created by EDI\Parser()

TEXT OUTPUT

$analyser->process($parsed); // returns text

Or

$analyser->process($parsed, $rawSegments);
  • $rawSegments (optional) contains the 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.

$analyser->process($parsed);
$json = $analyser->getJson();

EDI\Reader

Read from EDI file requested segment element values.

INPUT

$r = new Reader($x);
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPreperation();

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->get());
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPreperation();

OUTPUT Errors

$c->errors();

Array

$c->get();

EDI\Interpreter

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();

$mapping = new EDI\Mapping\MappingProvider('D95B');

$analyser = new EDI\Analyser();
$segs = $analyser->loadSegmentsXml($mapping->getSegments());
$svc = $analyser->loadSegmentsXml($mapping->getServiceSegments(3));

$interpreter = new EDI\Interpreter($mapping->getMessage('CODECO'), $segs, $svc);
$prep = $interpreter->prepare($edi);

OUTPUT

Json

$interpreter->getJson()

Json for interchange service segments (UNB / UNZ)

$interpreter->getJsonServiceSegments()

Errors (per message)

$interpreter->getErrors()

Example

Edifact

DTM+7:201309200717:203'

Array

['DTM',['7','201309200717','203']]

Testing

The package should be required with composer, alongside edifact-mapping. The tests then can be run simply with phpunit in the root of the package.

Notes

Valid characters are: A-Za-z0-9.,-()/'+:=?!"%&*;<> UNECE

edifact's People

Contributors

sabas avatar uldisn avatar voku avatar emilv avatar homer8173 avatar tophsic avatar wendelin avatar mtdavidson avatar puggan avatar xiro avatar jbrooksuk avatar killerkent avatar swiffer avatar michaelachrisco avatar sahat81 avatar sunmar avatar lazytyper avatar groberts84 avatar repat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.