<?php
namespace App\Amadeus\FileParser; class Line_B extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ ['name'=> 'MSGTAG', 'val' => 'B-', 'type' => 'AN', 'req' => 'M', 'len' => 2,], ['name'=> 'ENTRY', 'type' => 'AN', 'req' => 'M', 'len_min' => 2, 'len_max' => 100,], ]; protected function postParse() { parent::postParse(); $parts = explode('/', $this->tree['ENTRY']); $this->tree['_ENTRY']['command'] = array_shift($parts); $segments = []; $passengers = []; $lines = []; $unhandled = []; $assocConvertor = \App\Utils\BaseParser\Utils\AssociationToArrayConvertor::getInstance(); $xtr = new \App\Utils\BaseParser\Utils\Extractor\Single(); foreach ($parts as $part) { if ($part === '') { continue; } if ($m = $xtr->findAndStore('/^S(?P<assoc>[0-9,\-]+)$/', $part)) { $segments = array_merge($segments, $assocConvertor->extractFromDashNotation($m->get('assoc'))); } elseif ($m = $xtr->findAndStore('/^(?:P|T|M)(?P<assoc>[0-9,\-]+)$/', $part)) { $passengers = array_merge($passengers, $assocConvertor->extractFromDashNotation($m->get('assoc'))); } elseif ($m = $xtr->findAndStore('/^L(?P<assoc>[0-9,\-]+)$/', $part)) { $lines = array_merge($lines, $assocConvertor->extractFromDashNotation($m->get('assoc'))); } elseif ($part === 'RT') { $this->tree['_ENTRY']['readyToTicket'] = true; } elseif ($part === 'ET') { $this->tree['_ENTRY']['electronicTicket'] = true; } else { $unhandled[] = $part; } } if ($segments) { $this->tree['_ENTRY']['SEGASS'] = array_values(array_unique($segments)); } if ($passengers) { $this->tree['_ENTRY']['PSGASS'] = array_values(array_unique($passengers)); } if ($lines) { $this->tree['_ENTRY']['LINEASS'] = array_values(array_unique($lines)); } if ($unhandled) { $this->tree['_ENTRY']['unhandled'] = $unhandled; } } } 