<?php
namespace App\GdsSalesReport\Parser; class TraverserFactory { use \App\Utils\BaseParser\SingletonTrait; public function getParser($filepath, $fileType) { $fileFormats = array_filter($this->getFileFormats()->getAll(), function($fmt) use($fileType) { return $fmt->code == $fileType; }); $fmt = reset($fileFormats); $class = $fmt->class; $parser = new $class(); $parser->loadFile($filepath); return $parser; } public function getFileFormats() { $fileFormats = new \App\GdsSalesReport\Parser\FileFormats\FileFormats(); $fmt = new \App\GdsSalesReport\Parser\FileFormats\FileFormat(); $fmt->code = 'amadeus'; $fmt->label = 'Amadeus'; $fmt->priority = 10; $fmt->class = '\App\GdsSalesReport\Parser\Parsers\Amadeus'; $fileFormats->append($fmt); $fmt = new \App\GdsSalesReport\Parser\FileFormats\FileFormat(); $fmt->code = 'sabre'; $fmt->label = 'Sabre'; $fmt->priority = 10; $fmt->class = '\App\GdsSalesReport\Parser\Parsers\Sabre'; $fileFormats->append($fmt); $fmt = new \App\GdsSalesReport\Parser\FileFormats\FileFormat(); $fmt->code = 'arc'; $fmt->label = 'ARC'; $fmt->priority = 10; $fmt->class = '\App\GdsSalesReport\Parser\Parsers\ARC'; $fileFormats->append($fmt); \Engine\Plugins\Manager::getInstance()->executeEvent('App\GdsSalesReport\Parser\TraverserFactory-getFileFormats', [ 'fileFormats' => $fileFormats, ] ); return $fileFormats; } } 