<?php
namespace App\Amadeus\FileParser; class Line_G extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ [ 'name'=> 'MSGTAG', 'val' => 'G-', 'type' => 'AN', 'req' => 'M', 'len' => 2,], [ 'name'=> 'INTIND', 'type' => 'AN', 'req' => 'M', 'len' => 3,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], [ 'name'=> 'SALEIND', 'type' => 'AN', 'len' => 4,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], [ 'name'=> 'ORG', 'type' => 'AN', 'req' => 'M', 'len' => 3,], [ 'name'=> 'DEST', 'type' => 'AN', 'req' => 'M', 'len' => 3,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], [ 'name'=> 'DOMISO', 'type' => 'AN', 'len' => 2,], ]; protected $structure_TD_9314 = [ [ 'name'=> 'MSGTAG', 'val' => 'G-', 'type' => 'AN', 'req' => 'M', 'len' => 2,], [ 'name'=> 'INTIND', 'type' => 'AN', 'req' => 'M', 'len' => 3,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], [ 'name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ]; public function parse() { if (preg_match("/^G-[\s]+\;\;\;$/", $this->content)) { $parsed = false; if (!$parsed) { try { $this->tree = $this->parseFromStructure($this->structure_TD_9314, $this->content); $parsed = true; } catch (\App\Amadeus\FileParser\ParserException $ex) {} } if (!$parsed) { throw new \App\Amadeus\FileParser\ParserException("Cannot extract data from this ATF line"); } } else { $this->tree = $this->parseFromStructure($this->structure, $this->content); } $this->postParse(); return $this; } protected function postParse() { parent::postParse(); $this->tree['DOMISO'] = trim((string)$this->tree['DOMISO']); $extern = ($this->tree['INTIND'][0]=='X' && !$this->tree['DOMISO']); $EU = ($this->tree['INTIND'][0]=='X' && $this->tree['DOMISO']=='EU'); $intern = ($this->tree['INTIND'][0]!='X' && $this->tree['DOMISO'] && $this->tree['DOMISO']!='EU'); $this->tree['type'] = ($intern?'intern':($EU?'EU':($extern?'extern':null))); } } 