EDI\Interpreter::processSegment PHP Method

processSegment() private method

Add human readable keys as in Analyser
private processSegment ( $segment, $xmlMap, $segmentIdx, &$errors = null )
$segment
    private function processSegment($segment, $xmlMap, $segmentIdx, &$errors = null)
    {
        $id = $segment[0];
        $jsonsegment = [];
        if (isset($xmlMap[$id])) {
            $attributes = $xmlMap[$id]['attributes'];
            $details_desc = $xmlMap[$id]['details'];
            $jsonelements = ["segmentIdx" => $segmentIdx, "segmentCode" => $id];
            foreach ($segment as $idx => $detail) {
                $n = $idx - 1;
                if ($idx == 0) {
                    continue;
                }
                if (!isset($details_desc[$n])) {
                    $errors[] = ["text" => $this->messageTextConf['TOOMANYELEMENTS'], "position" => $segmentIdx, "segmentId" => $id];
                    $jsonelements["Extension" . $n] = $detail;
                    continue;
                }
                $d_desc_attr = $details_desc[$n]['attributes'];
                $jsoncomposite = [];
                if (isset($details_desc[$n]['details']) && $detail !== '') {
                    $sub_details_desc = $details_desc[$n]['details'];
                    if (!is_array($detail)) {
                        $d_sub_desc_attr = $sub_details_desc[0]['attributes'];
                        $jsoncomposite[$d_sub_desc_attr['name']] = $detail;
                    } else {
                        foreach ($detail as $d_n => $d_detail) {
                            if (!isset($sub_details_desc[$d_n])) {
                                $errors[] = ["text" => $this->messageTextConf['TOOMANYELEMENTS_COMPOSITE'], "position" => $segmentIdx . "/" . $idx, "segmentId" => $id];
                                $jsoncomposite["CompositeExtension" . $d_n] = $d_detail;
                                continue;
                            }
                            $d_sub_desc_attr = $sub_details_desc[$d_n]['attributes'];
                            if (!isset($jsoncomposite[$d_sub_desc_attr['name']])) {
                                //New
                                $jsoncomposite[$d_sub_desc_attr['name']] = $d_detail;
                            } elseif (is_string($jsoncomposite[$d_sub_desc_attr['name']])) {
                                // More data than one string
                                $jsoncomposite[$d_sub_desc_attr['name']] = array($jsoncomposite[$d_sub_desc_attr['name']], $d_detail);
                            } else {
                                // More and more
                                $jsoncomposite[$d_sub_desc_attr['name']][] = $d_detail;
                            }
                        }
                    }
                } else {
                    $jsoncomposite = $detail;
                }
                $jsonelements[$d_desc_attr['name']] = $jsoncomposite;
            }
            $jsonsegment['key'] = $attributes['name'];
            $jsonsegment['value'] = $jsonelements;
        } else {
            $jsonsegment['key'] = 'UnrecognisedType';
            $jsonsegment['value'] = $segment;
        }
        return $jsonsegment;
    }