Skip to content

Commit 87ee7ab

Browse files
committed
Patch UNT when missing; add flag to disable the template function
1 parent 4fcac7a commit 87ee7ab

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
codeCoverage/*
22
/vendor
3+
/build
34
composer.lock

src/EDI/Interpreter.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class Interpreter
3939
'SG1' => [['TDT', '20', 'XXX']],
4040
];
4141

42+
/**
43+
*
44+
*/
45+
private $patchFiles = true;
46+
4247
/**
4348
* @var \SimpleXMLElement
4449
*/
@@ -113,6 +118,11 @@ public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array
113118
};
114119
}
115120

121+
public function togglePatching(bool $flag)
122+
{
123+
$this->patchFiles = $flag;
124+
}
125+
116126
/**
117127
* Patch the error messages array
118128
*
@@ -305,7 +315,12 @@ private function splitMessages(&$parsed, &$errors): array
305315
];
306316
}
307317
$service['UNZ'] = $segment;
308-
318+
if ($this->patchFiles && $hasMessageDelimiters > 0) {
319+
$segment = ['UNT', '0', '1'];
320+
$hasMessageDelimiters--;
321+
$tmpmsg[] = $segment;
322+
$messages[] = $tmpmsg;
323+
}
309324
break;
310325
case 'UNH':
311326
$hasMessageDelimiters = 0;
@@ -416,7 +431,7 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$
416431
) {
417432
$elmType = $elm['id']->__toString();
418433
$fixed = false;
419-
if (isset($this->groupTemplates[$elmType])) {
434+
if ($this->patchFiles && isset($this->groupTemplates[$elmType])) {
420435
\array_splice($message, $segmentIdx, 0, $this->groupTemplates[$elmType]);
421436
$fixed = true;
422437
}
@@ -482,7 +497,7 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int
482497
$elmType = (string) $elm['id'];
483498
}
484499

485-
if (isset($this->segmentTemplates[$elmType])) {
500+
if ($this->patchFiles && isset($this->segmentTemplates[$elmType])) {
486501
$jsonMessage = $this->processSegment($this->segmentTemplates[$elmType], $this->xmlSeg, $segmentIdx, $errors);
487502
$fixed = true;
488503
$this->doAddArray($array, $jsonMessage);

0 commit comments

Comments
 (0)