<?php
namespace App\Amadeus\FileParser; class Line_AMS extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ ['name'=> 'MSGTAG', 'val' => 'AMS', 'type' => 'AN', 'req' => 'M', 'len' => 3,], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'TYPEADRS', 'type' => 'AN', 'len' => 1,], ['name'=> '_', 'type' => 'customCall', 'call'=> 'fields',], ['name'=> 'PSGASS', 'val' => ';P', 'type' => 'ASSOC',], ]; function parseFromStructure_v2_custom_fields($tree, $struct, $content, $index, $options){ $matches = []; $regexp = "^" ."(\;CY-(?P<COMPANY>[^;]*))?" ."(\;NA-(?P<NAME>[^;]*))?" ."(\;A1-(?P<ADRS1>.*?(?=\;(A2)-)))?" ."(\;A2-(?P<ADRS2>.*?(?=\;(PO|ZP|CI|ST|CO)-)))?" ."(\;PO-(?P<POBOX>[^;]*))?" ."(\;ZP-(?P<ZP>[^;]*))?" ."(\;CI-(?P<CITY>[^;]*))?" ."(\;ST-(?P<STATE>[^;]*))?" ."(\;CO-(?P<COUNTRY>[^;]*))?"; preg_match("/{$regexp}/", substr($content, $index), $matches); if ($matches) { $tree['COMPANY'] = $matches['COMPANY']; $tree['NAME'] = $matches['NAME']; $tree['ADRS1'] = $matches['ADRS1']; $tree['ADRS2'] = $matches['ADRS2']; $tree['POBOX'] = $matches['POBOX']; $tree['ZP'] = $matches['ZP']; $tree['CITY'] = $matches['CITY']; $tree['STATE'] = $matches['STATE']; $tree['COUNTRY'] = $matches['COUNTRY']; $ret = []; $ret['index'] = $index+strlen($matches[0]); $ret['tree'] = $tree; $ret['skipStructIndexIncrement'] = true; return $ret; } return null; } } 