feat: refactoring of xml parsers
This commit is contained in:
1 parent
11f1508640
commit
6730c243f6
49 files changed
+1414
-1235
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class RoomsParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $result): array
|
||||
{
|
||||
$rooms = [];
|
||||
|
||||
$result->each(function (Crawler $node) use (&$rooms) {
|
||||
$room = new Room();
|
||||
$room->id = (int) $node->attr('idzimmer');;
|
||||
$room->label = $node->attr('zimmer');
|
||||
$room->category = $node->attr('kategorie');
|
||||
$room->boardId = (int) $node->attr('idverpflegung');
|
||||
$room->dateFrom = $node->attr('anreise') ?
|
||||
$this->stringToDate($node->attr('anreise')) : null;
|
||||
$room->dateTo = $node->attr('abreise') ?
|
||||
$this->stringToDate($node->attr('abreise')) : null;
|
||||
$room->totalCount = (int) $node->attr('anzahl');
|
||||
$room->minPax = (int) $node->attr('minpax');
|
||||
$room->maxPax = (int) $node->attr('maxpax');
|
||||
$room->board = $node->attr('verpflegung');
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$room->mapping = array_map('intval', $mapping);
|
||||
$room->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$room->individualPrice = array_combine($mapping, $individualPrices);
|
||||
|
||||
$rooms[$room->id] = $room;
|
||||
});
|
||||
|
||||
return $rooms;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user