-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Chemaclass/improve-example
Improve example
- Loading branch information
Showing
7 changed files
with
137 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
UNA:+.? ' | ||
UNB+UNOC:3+9457386:30+73130012:30+19101:118+8+MPM 2.19+1424' | ||
|
||
UNH+1+IFTMIN:S:93A:UN:PN001' | ||
BGM+340+56677786689+9' | ||
DTM+10:20191011:102' | ||
TSR+19+A4' | ||
CNT+7:0.51:KGM' | ||
CNT+11:1:PCE' | ||
RFF+CU:ValidationSet1' | ||
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' | ||
CTA+IC+:Person Name' | ||
COM+?+46980100:AL' | ||
COM+person.name@test.com:EM' | ||
GID+1+1' | ||
MEA+WT+G+KGM:0.62' | ||
MEA+VOL++MTQ:0' | ||
PCI+18+56677786689' | ||
UNT+18+1' | ||
|
||
UNH+2+IFTMIN:S:93A:UN:PN001' | ||
BGM+340+05055700896+9' | ||
DTM+10:20191011:102' | ||
TSR+19+A4' | ||
CNT+7:0.62:KGM' | ||
CNT+11:1:PCE' | ||
RFF+CU:ValidationSet2' | ||
TDT+20' | ||
NAD+CZ+0410106314:160:Z12++Company Returns+c/o Carrier AB+City1++12345+DE' | ||
NAD+CN+++Person Name+Street Nr 2+City2++12345+DE' | ||
CTA+IC+:Person Name' | ||
COM+?+46980100:AL' | ||
COM+person.name@test.com:EM' | ||
GID+1+1' | ||
MEA+WT+G+KGM:0.62' | ||
MEA+VOL++MTQ:0' | ||
PCI+18+05055700896' | ||
UNT+19+2' | ||
|
||
UNZ+2+8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require dirname(__DIR__) . '/vendor/autoload.php'; | ||
|
||
use EdifactParser\EdifactParser; | ||
use EdifactParser\IO\ConsolePrinter; | ||
use EdifactParser\Segments\BGMBeginningOfMessage; | ||
use EdifactParser\Segments\CNTControl; | ||
use EdifactParser\Segments\DTMDateTimePeriod; | ||
use EdifactParser\Segments\MEADimensions; | ||
use EdifactParser\Segments\NADNameAddress; | ||
use EdifactParser\Segments\PCIPackageId; | ||
use EdifactParser\Segments\UNHMessageHeader; | ||
use EdifactParser\Segments\UNTMessageFooter; | ||
|
||
$fileContent = file_get_contents(__DIR__ . '/edifact-sample.edi'); | ||
$messages = EdifactParser::create()->parse($fileContent); | ||
|
||
$printer = ConsolePrinter::createWithHeaders([ | ||
UNHMessageHeader::class, | ||
BGMBeginningOfMessage::class, | ||
DTMDateTimePeriod::class, | ||
CNTControl::class, | ||
NADNameAddress::class, | ||
MEADimensions::class, | ||
PCIPackageId::class, | ||
UNTMessageFooter::class, | ||
]); | ||
|
||
foreach ($messages as $i => $message) { | ||
print "Message number: {$i}\n"; | ||
$printer->printMessage($message); | ||
print PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EdifactParser\IO; | ||
|
||
use EdifactParser\Segments\SegmentInterface; | ||
use EdifactParser\TransactionMessage; | ||
|
||
final class ConsolePrinter implements PrinterInterface | ||
{ | ||
/** @var string[] */ | ||
private array $segmentNames; | ||
|
||
public static function createWithHeaders(array $segmentNames): self | ||
{ | ||
return new self($segmentNames); | ||
} | ||
|
||
private function __construct(array $segmentNames) | ||
{ | ||
$this->segmentNames = $segmentNames; | ||
} | ||
|
||
public function printMessage(TransactionMessage $message): void | ||
{ | ||
foreach ($this->segmentNames as $segmentName) { | ||
$this->printSegment($message->segmentByName($segmentName)); | ||
} | ||
} | ||
|
||
/** @var SegmentInterface[] */ | ||
private function printSegment(array $segments): void | ||
{ | ||
$first = $segments[array_key_first($segments)]; | ||
print sprintf("> %s:\n", $first->tag()); | ||
|
||
foreach ($segments as $segment) { | ||
print sprintf( | ||
" %s |> %s \n", | ||
str_pad($segment->subId(), 3), | ||
json_encode($segment->rawValues()) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EdifactParser\IO; | ||
|
||
use EdifactParser\TransactionMessage; | ||
|
||
interface PrinterInterface | ||
{ | ||
public function printMessage(TransactionMessage $message): void; | ||
} |