-
Notifications
You must be signed in to change notification settings - Fork 0
/
XMLParser.php
34 lines (26 loc) · 1.37 KB
/
XMLParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use App\PruebaTecnica\Entity\Segment;
class Parser
{
public function parseFlights(string $xmlString): array
{
$xml = simplexml_load_string($xmlString);
$data = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://www.iata.org/IATA/EDIST/2017.2');
$flights = $data->AirShoppingRS->DataLists->FlightSegmentList->FlightSegment;
$flightList = array();
foreach ($flights as $flight) {
$segment = new Segment();
$segment->setOriginCode($flight->Departure->AirportCode);
$segment->setOriginName($flight->Departure->AirportName);
$segment->setDestinationCode($flight->Arrival->AirportCode);
$segment->setDestinationName($flight->Arrival->AirportName);
$segment->setStart(new DateTime($flight->Departure->Date . $flight->Departure->Time));
$segment->setEnd(new DateTime($flight->Arrival->Date . $flight->Arrival->Time));
$segment->setTransportNumber($flight->MarketingCarrier->FlightNumber);
$segment->setCompanyCode($flight->MarketingCarrier->AirlineID);
$segment->setCompanyName($flight->MarketingCarrier->Name);
$flightList[] = $segment;
}
return $flightList;
}
}