@@ -15,6 +15,9 @@ class Interpreter
15
15
private $ errors ;
16
16
private $ msgs ;
17
17
private $ serviceSeg ;
18
+
19
+ private $ comparisonFunction ;
20
+
18
21
public $ messageTextConf = [
19
22
'MISSINGREQUIREDSEGMENT ' => "Missing required segment " ,
20
23
'NOTCONFORMANT ' => "It looks like that this message isn't conformant to the mapping provided. (Not all segments were added) " ,
@@ -41,6 +44,20 @@ public function __construct($xmlMsg, $xmlSeg, $xmlSvc, $messageTextConf = null)
41
44
$ this ->messageTextConf = array_replace ($ this ->messageTextConf , $ messageTextConf );
42
45
}
43
46
$ this ->errors = [];
47
+
48
+ $ this ->comparisonFunction = function ($ segment , $ elm ) {
49
+ return $ segment [0 ] == $ elm ['id ' ];
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Split multiple messages and process
55
+ *
56
+ * @param $func A function accepting two arguments, first is the segment array, then the element definition
57
+ * @return void
58
+ */
59
+ public function setComparisonFunction (callable $ func ) {
60
+ $ this ->comparisonFunction = $ func ;
44
61
}
45
62
46
63
/**
@@ -178,7 +195,7 @@ private function loopMessage($message, $xml, &$errors)
178
195
* Process an XML Group
179
196
*
180
197
*/
181
- public function processXmlGroup ($ elm , $ message , &$ segmentIdx , &$ array , &$ errors )
198
+ private function processXmlGroup ($ elm , $ message , &$ segmentIdx , &$ array , &$ errors )
182
199
{
183
200
$ newGroup = [];
184
201
for ($ g = 0 ; $ g < $ elm ['maxrepeat ' ]; $ g ++) {
@@ -209,7 +226,7 @@ private function processXmlSegment($elm, $message, &$segmentIdx, &$array, &$erro
209
226
{
210
227
$ segmentVisited = false ;
211
228
for ($ i = 0 ; $ i < $ elm ['maxrepeat ' ]; $ i ++) {
212
- if ($ message [$ segmentIdx ][ 0 ] == $ elm[ ' id ' ] ) {
229
+ if (call_user_func ( $ this -> comparisonFunction , $ message [$ segmentIdx ], $ elm) ) {
213
230
$ jsonMessage = $ this ->processSegment ($ message [$ segmentIdx ], $ this ->xmlSeg , $ segmentIdx , $ errors );
214
231
$ segmentVisited = true ;
215
232
$ this ->doAddArray ($ array , $ jsonMessage );
0 commit comments