<?php
namespace App\Amadeus\StructureParser; class ClassBuilder { public static function buildObject($caller, $type, $subType) { $type = ucfirst($type); $class1 = "AmadeusStructureParser\\Plugins\\{$type}\\{$subType}"; if(class_exists($class1)){ return new $class1($caller); } $class2 = "App\\Amadeus\\StructureParser\\Structures\\{$type}\\{$subType}"; if(class_exists($class2)){ return new $class2($caller); } throw new \Exception("Cannot find a class named either {$class1} or {$class2}"); } public static function getPassengers($caller, $type) { return self::buildObject($caller, $type, 'Passengers'); } public static function getItinerary($caller, $type) { return self::buildObject($caller, $type, 'Itinerary'); } public static function getPrice($caller, $type) { return self::buildObject($caller, $type, 'Price'); } public static function getServiceDetails($caller, $type) { return self::buildObject($caller, $type, 'ServiceDetails'); } public static function getUser($caller, $type) { return self::buildObject($caller, $type, 'User'); } public static function getDocument($caller, $type) { return self::buildObject($caller, $type, 'Document'); } } 