<?php
namespace App\Worldspan\LineParser\Types\Line; class RG extends \App\Worldspan\LineParser\Types\WorldspanBaseLine { protected $extractRegexp = "/^(?P<rawData>G.+)/sm"; protected $children_default = [ ['key'=> 'key', 'type'=> 'Constant', 'len'=> 1, 'val'=> 'G', 'req'=> true,], ['key'=> 'CurrencyCodeOfFare', 'type'=> 'StringTrim', 'len'=> 3, 'req'=> false,], ['key'=> 'FareAmount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> '#015', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'Tax1CodeIdentifier', 'type'=> 'StringRaw', 'len'=> 3, 'req'=> false,], ['key'=> 'Tax1Amount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> '#018', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'Tax2CodeIdentifier', 'type'=> 'StringRaw', 'len'=> 3, 'req'=> false,], ['key'=> 'Tax2Amount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> '#021', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'Tax3CodeIdentifier', 'type'=> 'StringRaw', 'len'=> 3, 'req'=> false,], ['key'=> 'Tax3Amount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> '#024', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'CurrencyCodeOfTotalFare', 'type'=> 'StringTrim', 'len'=> 3, 'req'=> false,], ['key'=> 'TotalFareAmount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> '#027', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'CurrencyCodeOfEquivalentFare', 'type'=> 'StringTrim', 'len'=> 3, 'req'=> false,], ['key'=> 'EquivalentFareAmount', 'type'=> 'FloatRaw', 'len'=> 8, 'req'=> false,], ['key'=> 'CurrencyCodeOfEquivalentFare_alt', 'type'=> 'Constant', 'len'=> 1, 'val'=> '*', 'req'=> false,], ['key'=> '#030', 'type'=> 'Separator', 'req'=> false,], ['key'=> 'key', 'type'=> 'Constant', 'len'=> 2, 'val'=> 'LT', 'req'=> false,], ['key'=> 'InvoiceAirAmount', 'type'=> 'FloatRaw', 'len'=> [1, 9], 'req'=> false,], ]; protected $children_noFare = [ ['key'=> 'complex:1', 'type'=> 'Complex', 'merge'=>true, 'req'=> false, 'children'=> [ ['key'=> 'key', 'type'=> 'Constant', 'len'=> 10, 'val'=> 'G*\*\*\*\*', 'req'=> true,], ['key'=> 'noFare', 'type'=> 'InternalMarker', 'val'=> true, 'req'=> true,], ]], ]; protected function _extract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret, $originalRawData) { \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logCallStart($this, __METHOD__, func_get_args()); $m = $this->safeMatch($this->extractRegexp, $originalRawData); $this->rawData = $m->matches['rawData']; $ret->remainingGlobalData = substr($originalRawData, strlen($this->rawData)); $extracted = $ret; $ret->remainingBlockData = $this->rawData; if (!$extracted->extractedData) { $extracted = $this->_extract_children($ret, $this->children_noFare, $this->rawData, [$this, "_extract_children_callback_associativeArray"]); } $ret->remainingBlockData = $this->rawData; if (!$extracted->extractedData) { $extracted = $this->_extract_children($ret, $this->children_default, $this->rawData, [$this, "_extract_children_callback_associativeArray"]); } if ($extracted->extractedData) { $ret->remainingBlockData = false; } if (!$extracted->extractedData) { \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logCallEnd(); throw new \App\Utils\BaseParser\TextParser\Exception\MissingRequiredElementException("Don't know how o parse this RG line. No defined format matches it", null, null, $this); } \Engine\Debug\ParserCallTrace\ParserCallTrace::getInstance()->logCallEnd(); return $ret; } protected function postExtract(\App\Utils\BaseParser\TextParser\ExtractedBlock $ret) { for ($i=1; $i<=3; $i++) { if ($ret->extractedData["Tax{$i}CodeIdentifier"]) { $ret->extractedData["Tax{$i}CodeIdentifier"] = trim($ret->extractedData["Tax{$i}CodeIdentifier"]); if ($ret->extractedData["Tax{$i}CodeIdentifier"][0]=='X' && strlen($ret->extractedData["Tax{$i}CodeIdentifier"])==3) { $ret->extractedData["Tax{$i}CodeIdentifier"] = substr($ret->extractedData["Tax{$i}CodeIdentifier"], 1); } } } return $ret; } } 