<?php
namespace App\Amadeus\FileParser; class Line_S extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ ['name'=> 'MSGTAG', 'val' => 'S-', 'type' => 'AN', 'req' => 'M', 'len' => 2,], ['name'=> 'PSGNBR', 'type' => 'N', 'req' => 'M', 'len' => 2,], ['name' => 'SEATINFO', 'type' =>'composite', 'rep_min' =>0, 'rep_max' =>99, 'childs' => [ ['name'=> 'fld', 'type' => 'AN', 'req' => 'M',], ['name'=> 'DELIM', 'val' => ';', 'type' => 'AN', 'req' => 'M', 'len' => 1,], ]], ]; protected $SEATST = [ 'R' => 'Reserved', 'A' => 'Reserved and Boarding Pass issued', 'S' => 'Reserved only, Boarding Pass issuance restricted', 'B' => 'Reserved, Issue Boarding Pass (ATB)', 'P' => 'Unconfirmed seat preference (ATB)', ]; protected function extractSeatInfo($seatInfo, $v) { $m = []; preg_match("/^(?P<board>[^\/]*)\/(?P<seat>.*)$/i", $seatInfo, $m); $board = $m['board']; $seat = $m['seat']; if($board){ if(preg_match( "/^". "((?P<BRDPT>[^\.]*)\.)?". "((?P<BOARDL>[^\.]*)\.)?". "((?P<OFFPT>[^\.]*)\.)?". "((?P<OFFL>.*))?". "$/i", $board, $m)){ $v['BRDPT'] = $m['BRDPT']; $v['BOARDL'] = $m['BOARDL']; $v['OFFPT'] = $m['OFFPT']; $v['OFFL'] = $m['OFFL']; }else{ throw \App\Amadeus\FileParser\ParserException::internal("Unknown BOARD structure in the SEATINFO subtag, content '{$board}'"); } } if($seat){ if(preg_match( "/^". "((?P<SEATST>.{1}))?". "((?P<SEATNBR>[^\+]*)\+)?". "((?P<RAILSEAT>[^\.]*)\.)?". "((?P<SMOKE>S|N|\s))?". "$/i", $seat, $m)){ $v['SEATST'] = $m['SEATST']; $v['SEATNBR'] = $m['SEATNBR']; $v['RAILSEAT'] =$m['RAILSEAT']; $v['SMOKE'] = trim($m['SMOKE']); $v['SEATST_'] = $this->SEATST[$v['SEATST']]; }else{ throw \App\Amadeus\FileParser\ParserException::internal("Unknown SEAT structure in the SEATINFO subtag, content '{$seat}'"); } } return $v; } protected function postParse() { parent::postParse(); if($this->tree['SEATINFO']){ foreach($this->tree['SEATINFO'] as $k=>$v){ if($v['fld']){ $change_of_gaugesArr = explode(",", $v['fld']); foreach($change_of_gaugesArr as $gaugeIndex=>$c_o_g){ $seat = $this->extractSeatInfo($c_o_g, []); if($gaugeIndex==0){ $v = $seat; }else{ $v['change_of_gauge'][] = $seat; } } $this->tree['SEATINFO'][$k] = $v; } } $this->tree['SEATINFO'] = self::rtrimArr($this->tree['SEATINFO']); } } } 