<?php
namespace App\Amadeus\FileParser; class Line_ATF extends \App\Amadeus\FileParser\LineAbstract { protected $structure_V620 = [ ['name'=> 'MSGTAG', 'val' => 'ATF-', 'type' => 'AN', 'req' => 'M', 'len' => 4,], ['name'=> 'CURFEE', 'type' => 'AN', 'len' => 3,], ['name'=> 'FEETOTL', 'type' => 'NF', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'CURGDT', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'GRDTOTL', 'type' => 'NF', 'req' => 'M', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name' => 'FEEFLD', 'type' =>'composite', 'rep_min' =>1, 'rep_max' =>99, 'childs' => [ ['name'=> 'FEEC', 'type' => 'AN', 'req' => 'M', 'len' => 2,], ['name'=> 'FEESC', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'FEECN', 'type' => 'AN', 'req' => 'M', 'len_min' => 1, 'len_max' => 10,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'FCURR', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'FEEA', 'type' => 'NF', 'req' => 'M', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'FEETCUR', 'type' => 'AN', 'len' => 3,], ['name'=> 'FEETA', 'type' => 'N', 'len' => 11,], ['name'=> 'FEETC', 'type' => 'AN', 'requires' => ['FEETA'], 'len' => 2,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ]], ]; protected $structure_V623 = [ ['name'=> 'MSGTAG', 'val' => 'ATF-', 'type' => 'AN', 'req' => 'M', 'len' => 4,], ['name'=> 'CURFEE', 'type' => 'AN', 'len' => 3,], ['name'=> 'FEETOTL', 'type' => 'NF', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'CURGDT', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'GRDTOTL', 'type' => 'NF', 'req' => 'M', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name' => 'FEEFLD', 'type' =>'customCall', 'call'=> 'FEEFLD', 'rep_min' =>1, 'rep_max' =>99,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'FEETTCUR', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'FEETTA', 'type' => 'NF', 'req' => 'M',], ]; protected $structure_02 = [ ['name'=> 'MSGTAG', 'val' => 'ATF-', 'type' => 'AN', 'req' => 'M', 'len' => 4,], ['name'=> 'CURFEE', 'type' => 'AN', 'len' => 3,], ['name'=> 'FEETOTL', 'type' => 'N', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'CURGDT', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'GRDTOTL', 'type' => 'N', 'req' => 'M', 'len' => 11,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'len' => 1,], ['name'=> 'FCURR', 'type' => 'AN', 'len' => 3,], ['name'=> 'FEEA', 'type' => 'N', 'len' => 11,], ]; public function isValid(){ if(strpos($this->content, "ATF-")===0){ return $this; } return false; } function parseFromStructure_v2_custom_FEEFLD($tree, $struct, $content, $index, $options){ $regexp = "(?P<FEEC>[A-Z]{2})" ."(?P<FEESC>[A-Z0-9]{3})" .";" ."(?P<FEECN>[^;]+)?" .";" ."(?P<FCURR>[A-Z]{3})" ."(?P<FEEA>[0-9\.]*)[\s]*" .";" ."(" ."(?P<FEETCUR>[A-Z]{3})" ."(?P<FEETA>[0-9\.]*)[\s]*" .";" .")?" ."(" ."(?P<FEETC>[A-Z]{2})[\s]*" .";" .")?" .""; $matches = []; preg_match("/^{$regexp}/", substr($content, $index), $matches); if($matches){ $tree['FEEC'] = $matches['FEEC']; $tree['FEESC'] = $matches['FEESC']; $tree['FEECN'] = $matches['FEECN']; $tree['FCURR'] = $matches['FCURR']; $tree['FEEA'] = (float)$matches['FEEA']; $tree['FEETCUR'] = $matches['FEETCUR']; $tree['FEETA'] = (float)$matches['FEETA']; $tree['FEETC'] = $matches['FEETC']; $ret = []; $ret['index'] = $index+strlen($matches[0]); $ret['tree'] = $tree; return $ret; } return null; } public function parse() { if(strlen($this->content)>50){ $parsed = false; if(!$parsed){ try{ $this->tree = $this->parseFromStructure($this->structure_V620, $this->content); $parsed = true; }catch(\App\Amadeus\FileParser\ParserException $ex){} } if(!$parsed){ try{ $this->tree = $this->parseFromStructure($this->structure_V623, $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_02, $this->content); } $this->postParse(); return $this; } protected function postParse() { parent::postParse(); if($this->tree['FEEFLD']){ $this->tree['FEEFLD'] = self::rtrimArr($this->tree['FEEFLD']); } } } 