44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\ApiResponseParser;
|
|
|
|
use App\BusProNet\Model\BaseData;
|
|
use App\BusProNet\Model\MutableField;
|
|
|
|
class MutableFieldsResponseParser
|
|
{
|
|
use ResponseParserTrait;
|
|
|
|
public function parse(\SimpleXMLElement $xml): BaseData
|
|
{
|
|
$mutableFields = [];
|
|
|
|
foreach ($xml->änderungen->änderung as $item) {
|
|
$attributes = $item->attributes();
|
|
|
|
$type = match ((string) $attributes['art']) {
|
|
'anzahl_teilnehmer' => 'participant_count',
|
|
'beförderung' => 'transportation',
|
|
'zustieg' => 'pickup',
|
|
'unterbringung' => 'accommodation',
|
|
'zusatzleistung' => 'services',
|
|
'teilnehmerdaten' => 'participant_data',
|
|
default => false,
|
|
};
|
|
|
|
if (false === $type) {
|
|
continue;
|
|
}
|
|
|
|
$mutableField = new MutableField($type, $this->stringToBool((string) $attributes['möglich']));
|
|
|
|
if ($attributes['möglichbiszum']) {
|
|
$mutableField->mutableBefore = $this->stringToDate((string) $attributes['möglichbiszum']);
|
|
}
|
|
|
|
$mutableFields[$type] = $mutableField;
|
|
}
|
|
|
|
return new BaseData($mutableFields);
|
|
}
|
|
} |