<?php
namespace App\Amadeus\FileParser; class Line_AB extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ [ 'name'=> 'MSGTAG', 'val' => 'AB', 'type' => 'AN', 'req' => 'M', 'len' => 2,], [ 'name'=> 'BILLADDR', 'type' => 'AN', 'req' => 'M',], [ 'name'=> 'PSGASS', 'val' => ';P', 'type' => 'ASSOC', ], ]; public function isValid() { if (strpos($this->content, 'AB')===0 && strpos($this->content, 'ABS;')===false) { return $this; } return false; } protected function handler_LineNotCompletlyProcessed($index, $content, $structIndex, $contentLength, $tree) { return $tree; } protected function postParse() { parent::postParse(); if ($this->tree['BILLADDR']) { $m = []; preg_match("/^[\s]*". "(CY-(?P<corporate>[^\/]*)(\/)?)?". "(NA-(?P<clientName>[^\/]*)(\/)?)?". "(A1-(?P<address>[^\/]*)(\/)?)?". "(A2-(?P<address2>[^\/]*)(\/)?)?". "(ZP-(?P<zipCode>[^\/]*)(\/)?)?". "(CI-(?P<city>[^\/]*)(\/)?)?". "(ST-(?P<state>[^\/]*)(\/)?)?". "(CO-(?P<country>[^\/]*)(\/)?)?". "$/i", $this->tree['BILLADDR'], $m); if ($m) { $this->tree['corporate'] = trim(($m['corporate']?:'')); $this->tree['clientName'] = trim(($m['clientName']?:'')); if ($m['address2']) { $repl = [ '/[\s]*,[\s]*$/', '/^[\s]+/', '/[\s]+$/', '/[\s]{2,}/', ]; $this->tree['address'] = sprintf("%s, %s", preg_replace($repl, "", ($m['address']?:'')), preg_replace($repl, "", ($m['address2']?:'')) ); } else { $this->tree['address'] = trim($m['address']??''); } $this->tree['zipCode'] = trim(($m['zipCode']?:'')); $this->tree['city'] = trim(($m['city']?:'')); $this->tree['state'] = trim(($m['state']?:'')); $this->tree['country'] = trim(($m['country']?:'')); } else { $this->tree['address'] = trim($this->tree['BILLADDR']); } } } } 