feat: refactoring of xml parsers
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class BookingsParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $result): BaseData
|
||||
{
|
||||
$bookings = [];
|
||||
$items = $result->filterXPath('//vorgaenge/vorgang');
|
||||
|
||||
if (0 === $items->count()) {
|
||||
return new BaseData($bookings);
|
||||
}
|
||||
|
||||
$items->each(function (Crawler $node) use (&$bookings) {
|
||||
$booking = new Booking();
|
||||
|
||||
$booking->id = $this->getIntOrNullValue($node->filterXPath('//id'));
|
||||
$booking->bookingNumber = $this->getIntOrNullValue($node->filterXPath('//vorgangsnummer'));
|
||||
$booking->status = $this->getStringOrNullValue($node->filterXPath('//status'));
|
||||
$booking->participantCount = $this->getIntOrNullValue($node->filterXPath('//personen'));
|
||||
$booking->price = $this->stringToFloat($this->getStringOrNullValue($node->filterXPath('//preis')));
|
||||
$booking->bookingDate = $this
|
||||
->stringToDateTime($this->getStringOrNullValue($node->filterXPath('//buchungsdatum')));
|
||||
$booking->travel = $this->getStringOrNullValue($node->filterXPath('//reise'));
|
||||
$booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise'));
|
||||
$booking->travelDate = $this
|
||||
->stringToDate($this->getStringOrNullValue($node->filterXPath('//reisedatum')));
|
||||
$booking->document = $this
|
||||
->stringToBool($this->getStringOrNullValue($node->filterXPath('//reisedokument')));
|
||||
$booking->payment = $this
|
||||
->stringToFloat($this->getStringOrNullValue($node->filterXPath('//zahlung')));
|
||||
|
||||
$bookings[] = $booking;
|
||||
});
|
||||
|
||||
return new BaseData($bookings);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user