@@ -23,7 +23,7 @@ class Interpreter
23
23
'MISSINGMESSAGEDELIMITER ' => 'The message has at least one UNH or UNT missing ' ,
24
24
'TOOMANYSEGMENTS ' => 'The message has some additional segments beyond the maximum repetition allowed ' ,
25
25
'TOOMANYGROUPS ' => 'The message has some additional groups beyond the maximum repetition allowed ' ,
26
- 'SPURIOUSSEGMENT ' => 'This segment is spurious '
26
+ 'SPURIOUSSEGMENT ' => 'This segment is spurious ' ,
27
27
];
28
28
29
29
/**
@@ -160,16 +160,17 @@ public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array
160
160
public function togglePatching (bool $ flag )
161
161
{
162
162
$ this ->patchFiles = $ flag ;
163
+
163
164
return $ this ;
164
165
}
165
166
166
-
167
167
/**
168
168
* @return void
169
169
*/
170
170
public function toggleSegmentGroup (bool $ flag )
171
171
{
172
172
$ this ->segmentGroup = $ flag ;
173
+
173
174
return $ this ;
174
175
}
175
176
@@ -179,6 +180,7 @@ public function toggleSegmentGroup(bool $flag)
179
180
public function forceArrayWhenRepeatable (bool $ flag )
180
181
{
181
182
$ this ->forceArrayWhenRepeatable = $ flag ;
183
+
182
184
return $ this ;
183
185
}
184
186
@@ -191,6 +193,7 @@ public function forceArrayWhenRepeatable(bool $flag)
191
193
public function setMessageTextConf (array $ messageTextConf )
192
194
{
193
195
$ this ->messageTextConf = \array_replace ($ this ->messageTextConf , $ messageTextConf );
196
+
194
197
return $ this ;
195
198
}
196
199
@@ -203,6 +206,7 @@ public function setMessageTextConf(array $messageTextConf)
203
206
public function setSegmentTemplates (array $ segmentTemplates )
204
207
{
205
208
$ this ->segmentTemplates = $ segmentTemplates ;
209
+
206
210
return $ this ;
207
211
}
208
212
@@ -215,6 +219,7 @@ public function setSegmentTemplates(array $segmentTemplates)
215
219
public function setGroupTemplates (array $ groupTemplates )
216
220
{
217
221
$ this ->groupTemplates = $ groupTemplates ;
222
+
218
223
return $ this ;
219
224
}
220
225
@@ -227,6 +232,7 @@ public function setGroupTemplates(array $groupTemplates)
227
232
public function setCodes (array $ codes )
228
233
{
229
234
$ this ->codes = $ codes ;
235
+
230
236
return $ this ;
231
237
}
232
238
@@ -239,6 +245,7 @@ public function setCodes(array $codes)
239
245
public function setComparisonFunction (callable $ func )
240
246
{
241
247
$ this ->comparisonFunction = $ func ;
248
+
242
249
return $ this ;
243
250
}
244
251
@@ -251,6 +258,7 @@ public function setComparisonFunction(callable $func)
251
258
public function setReplacementFunction (callable $ func )
252
259
{
253
260
$ this ->replacementFunction = $ func ;
261
+
254
262
return $ this ;
255
263
}
256
264
@@ -267,6 +275,7 @@ public function toggleUseIdInsteadOfNameForOutput(bool $toggle)
267
275
} else {
268
276
$ this ->outputKey = 'name ' ;
269
277
}
278
+
270
279
return $ this ;
271
280
}
272
281
@@ -599,7 +608,7 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int
599
608
$ segmentVisited = true ;
600
609
$ this ->doAddArray ($ array , $ jsonMessage , (int ) $ elm ['maxrepeat ' ]);
601
610
$ segmentIdx ++;
602
- } else if ($ this ->replacementFunction !== null && $ replacementSegment = \call_user_func ($ this ->replacementFunction , $ message [$ segmentIdx ], $ elm )) {
611
+ } elseif ($ this ->replacementFunction !== null && $ replacementSegment = \call_user_func ($ this ->replacementFunction , $ message [$ segmentIdx ], $ elm )) {
603
612
//the function shall return false, true or a new segment
604
613
$ fixed = false ;
605
614
@@ -627,18 +636,20 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int
627
636
'segmentId ' => (string ) $ elm ['id ' ],
628
637
];
629
638
$ segmentIdx ++;
639
+
630
640
continue ;
631
641
} else {
632
642
if (! $ segmentVisited && isset ($ elm ['required ' ])) {
633
643
$ segmentVisited = true ;
634
- if (isset ($ message [$ segmentIdx+ 1 ]) && \call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx+ 1 ], $ elm )) {
644
+ if (isset ($ message [$ segmentIdx + 1 ]) && \call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx + 1 ], $ elm )) {
635
645
$ errors [] = [
636
646
'text ' => $ this ->messageTextConf ['SPURIOUSSEGMENT ' ].($ this ->patchFiles ? ' (skipped) ' : '' ),
637
647
'position ' => $ segmentIdx ,
638
648
'segmentId ' => (string ) $ message [$ segmentIdx ][0 ],
639
649
];
640
650
$ segmentIdx ++; //just move the index
641
651
$ i --; //but don't count as repetition
652
+
642
653
continue ;
643
654
}
644
655
@@ -672,8 +683,8 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int
672
683
$ loopMove = 0 ;
673
684
while (
674
685
isset ($ message [$ segmentIdx ]) &&
675
- \call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx+ $ loopMove ], $ elm ) &&
676
- (string )$ elm ['id ' ] !== $ this ->currentGroupHeader
686
+ \call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx + $ loopMove ], $ elm ) &&
687
+ (string ) $ elm ['id ' ] !== $ this ->currentGroupHeader
677
688
) {
678
689
$ errors [] = [
679
690
'text ' => $ this ->messageTextConf ['TOOMANYSEGMENTS ' ].($ this ->patchFiles ? ' (skipped) ' : '' ),
@@ -735,7 +746,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar
735
746
736
747
$ jsonelements = [
737
748
'segmentIdx ' => $ segmentIdx ,
738
- 'segmentCode ' => $ id
749
+ 'segmentCode ' => $ id,
739
750
];
740
751
741
752
if ($ this ->segmentGroup ) {
@@ -783,7 +794,9 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar
783
794
}
784
795
785
796
$ d_sub_desc_attr = $ sub_details_desc [$ d_n ]['attributes ' ];
786
-
797
+ //print_r($d_sub_desc_attr);
798
+ //print_r($d_detail);
799
+ //die();
787
800
if ($ this ->codes !== null && isset ($ this ->codes [$ d_sub_desc_attr ['id ' ]]) && is_array ($ this ->codes [$ d_sub_desc_attr ['id ' ]])) { //if codes is set enable translation of the value
788
801
if (isset ($ this ->codes [$ d_sub_desc_attr ['id ' ]][$ d_detail ])) {
789
802
$ d_detail = $ this ->codes [$ d_sub_desc_attr ['id ' ]][$ d_detail ];
@@ -859,9 +872,19 @@ public function rebuildArray()
859
872
if ($ this ->codes !== null ) {
860
873
throw new \LogicException ('Run the Interpreter without calling setCodes() ' );
861
874
}
875
+ $ unh = $ this ->serviceSeg ['interchangeHeader ' ];
876
+ unset($ unh ['segmentIdx ' ]);
877
+ unset($ unh ['segmentGroup ' ]);
878
+ $ unz = $ this ->serviceSeg ['interchangeTrailer ' ];
879
+ unset($ unz ['segmentIdx ' ]);
880
+ unset($ unz ['segmentGroup ' ]);
862
881
863
- return $ this ->recursionReconstruct ($ this ->ediGroups );
882
+ $ rebuilt = $ this ->recursionReconstruct ($ this ->ediGroups );
864
883
884
+ array_unshift ($ rebuilt , $ unh );
885
+ $ rebuilt [] = $ unz ;
886
+
887
+ return $ rebuilt ;
865
888
}
866
889
867
890
private function recursionReconstruct ($ tempArr )
@@ -875,7 +898,7 @@ private function recursionReconstruct($tempArr)
875
898
$ reconstructArr [$ k ] = $ i ;
876
899
}
877
900
} else {
878
- $ idx= $ arr ['segmentIdx ' ];
901
+ $ idx = $ arr ['segmentIdx ' ];
879
902
unset($ arr ['segmentIdx ' ]);
880
903
if ($ this ->segmentGroup ) {
881
904
unset($ arr ['segmentGroup ' ]);
@@ -884,6 +907,7 @@ private function recursionReconstruct($tempArr)
884
907
}
885
908
}
886
909
}
910
+
887
911
return $ reconstructArr ;
888
912
}
889
913
}
0 commit comments