<?php
namespace App\Amadeus\FileParser; class Line_RM extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ ['name'=> 'MSGTAG', 'val' => 'RM', 'type' => 'AN', 'req' => 'M', 'len' => 2,], ['name'=> 'RMTYPE', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ['name'=> 'PNRRMK', 'type' => 'AN', 'req' => 'M',], ['name'=> 'SEGASS', 'val' => ';S', 'type' => 'ASSOC',], ['name'=> 'PSGASS', 'val' => ';P', 'type' => 'ASSOC',], ]; protected function getStructByName($name) { foreach($this->structure as $struct) { if($struct['name']==$name) { return $struct; } } return null; } protected function hasStructByName($name) { return (bool)$this->getStructByName($name); } public function parse() { $matches = []; $regex = "/^"; $regex.= "(?P<MSGTAG>{$this->structure[0]['val']})"; if($this->hasStructByName('RMTYPE')) { $regex.= "(?P<RMTYPE>(\s|\*))"; } if($this->hasStructByName('PNRRMK')) { $regex.= "(?P<PNRRMK>.*?)"; } elseif($this->hasStructByName('INTRM')) { $regex.= "(?P<INTRM>.*?)"; } if($this->hasStructByName('SEGASS')) { $regex.= "(?P<SEGASS>\;S[0-9-,]+)?"; } if($this->hasStructByName('PSGASS')) { $regex.= "(?P<PSGASS>\;P[0-9-,]+)?"; } $regex.= "$/"; preg_match($regex, $this->content, $matches); $this->tree['MSGTAG'] = $matches['MSGTAG']; if($this->hasStructByName('RMTYPE')) { $this->tree['RMTYPE'] = $matches['RMTYPE']; } if($this->hasStructByName('PNRRMK')) { $this->tree['PNRRMK'] = $matches['PNRRMK']; } elseif($this->hasStructByName('INTRM')) { $this->tree['INTRM'] = $matches['INTRM']; } if($this->hasStructByName('SEGASS')) { $this->tree['SEGASS'] = $matches['SEGASS']; $struct = $this->getStructByName('SEGASS'); if($matches['SEGASS'] && ($v = $this->parseFromStructure_v2_generalAssoc($struct, $this->tree['SEGASS'], 0, []))){ $this->tree[$struct['name']] = $v['value']; } } if($this->hasStructByName('PSGASS')) { $this->tree['PSGASS'] = $matches['PSGASS']; $struct = $this->getStructByName('PSGASS'); if($matches['PSGASS'] && ($v = $this->parseFromStructure_v2_generalAssoc($struct, $this->tree['PSGASS'], 0, []))){ $this->tree[$struct['name']] = $v['value']; } } $this->postParse(); return $this; } } 