@@ -40,7 +40,7 @@ class Interpreter
40
40
];
41
41
42
42
/**
43
- *
43
+ * @var bool
44
44
*/
45
45
private $ patchFiles = true ;
46
46
@@ -84,13 +84,18 @@ class Interpreter
84
84
*/
85
85
private $ comparisonFunction ;
86
86
87
+ /**
88
+ * @var string
89
+ */
90
+ private $ outputKey = 'name ' ;
91
+
87
92
/**
88
93
* Split multiple messages and process
89
94
*
90
- * @param string $xmlMsg Path to XML Message representation
91
- * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml
92
- * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml
93
- * @param array|null $messageTextConf Personalisation of error messages
95
+ * @param string $xmlMsg Path to XML Message representation
96
+ * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml
97
+ * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml
98
+ * @param array|null $messageTextConf Personalisation of error messages
94
99
*/
95
100
public function __construct (string $ xmlMsg , array $ xmlSeg , array $ xmlSvc , array $ messageTextConf = null )
96
101
{
@@ -118,6 +123,11 @@ public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array
118
123
};
119
124
}
120
125
126
+ /**
127
+ * @param bool $flag
128
+ *
129
+ * @return void
130
+ */
121
131
public function togglePatching (bool $ flag )
122
132
{
123
133
$ this ->patchFiles = $ flag ;
@@ -171,6 +181,23 @@ public function setComparisonFunction(callable $func)
171
181
$ this ->comparisonFunction = $ func ;
172
182
}
173
183
184
+ /**
185
+ * Set to true if UNCEFACT XML ID should be used instead of names
186
+ *
187
+ * @param bool $toggle
188
+ *
189
+ * @return void
190
+ */
191
+ public function toggleUseIdInsteadOfNameForOutput (bool $ toggle )
192
+ {
193
+ if ($ toggle ) {
194
+ $ this ->outputKey = 'id ' ;
195
+ }
196
+ else {
197
+ $ this ->outputKey = 'name ' ;
198
+ }
199
+ }
200
+
174
201
/**
175
202
* Split multiple messages and process
176
203
*
@@ -601,32 +628,32 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar
601
628
}
602
629
603
630
$ d_sub_desc_attr = $ sub_details_desc [$ d_n ]['attributes ' ];
604
- if (!isset ($ jsoncomposite [$ d_sub_desc_attr [' name ' ]])) { //New
605
- $ jsoncomposite [$ d_sub_desc_attr [' name ' ]] = $ d_detail ;
606
- } elseif (\is_string ($ jsoncomposite [$ d_sub_desc_attr [' name ' ]])) { // More data than one string
607
- $ jsoncomposite [$ d_sub_desc_attr [' name ' ]] = [
608
- $ jsoncomposite [$ d_sub_desc_attr [' name ' ]],
631
+ if (!isset ($ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]])) { //New
632
+ $ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]] = $ d_detail ;
633
+ } elseif (\is_string ($ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]])) { // More data than one string
634
+ $ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]] = [
635
+ $ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]],
609
636
$ d_detail ,
610
637
];
611
638
} else { // More and more
612
- $ jsoncomposite [$ d_sub_desc_attr [' name ' ]][] = $ d_detail ;
639
+ $ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]][] = $ d_detail ;
613
640
}
614
641
}
615
642
} else {
616
643
$ d_sub_desc_attr = $ sub_details_desc [0 ]['attributes ' ];
617
- $ jsoncomposite [$ d_sub_desc_attr [' name ' ]] = $ detail ;
644
+ $ jsoncomposite [$ d_sub_desc_attr [$ this -> outputKey ]] = $ detail ;
618
645
}
619
646
} else {
620
647
$ jsoncomposite = $ detail ;
621
648
}
622
649
623
- if (\array_key_exists ($ d_desc_attr [' name ' ], $ jsonelements )) {
624
- $ jsonelements [$ d_desc_attr [' name ' ] . $ n ] = $ jsoncomposite ;
650
+ if (\array_key_exists ($ d_desc_attr [$ this -> outputKey ], $ jsonelements )) {
651
+ $ jsonelements [$ d_desc_attr [$ this -> outputKey ] . $ n ] = $ jsoncomposite ;
625
652
} else {
626
- $ jsonelements [$ d_desc_attr [' name ' ]] = $ jsoncomposite ;
653
+ $ jsonelements [$ d_desc_attr [$ this -> outputKey ]] = $ jsoncomposite ;
627
654
}
628
655
}
629
- $ jsonsegment ['key ' ] = $ attributes [' name ' ];
656
+ $ jsonsegment ['key ' ] = $ attributes [$ this -> outputKey ];
630
657
$ jsonsegment ['value ' ] = $ jsonelements ;
631
658
} elseif ($ xmlMap !== $ this ->xmlSvc ) {
632
659
$ jsonsegment = $ this ->processSegment ($ segment , $ this ->xmlSvc , $ segmentIdx , $ errors );
0 commit comments