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,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\MutableData;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class MutableDataParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $result): BaseData
|
||||
{
|
||||
$mutableFields = [];
|
||||
|
||||
$result
|
||||
->filterXPath('//änderungen/änderung')
|
||||
->each(function (Crawler $node) use (&$mutableFields) {
|
||||
$category = match ($node->attr('art')) {
|
||||
'anzahl_teilnehmer' => MutableData::CATEGORY_PARTICIPANT_COUNT,
|
||||
'beförderung' => MutableData::CATEGORY_TRANSPORTATION,
|
||||
'zustieg' => MutableData::CATEGORY_PICKUP,
|
||||
'unterbringung' => MutableData::CATEGORY_ACCOMMODATION,
|
||||
'zusatzleistung' => MutableData::CATEGORY_ADDITIONAL_SERVICES,
|
||||
'teilnehmerdaten' => MutableData::CATEGORY_PARTICIPANT_DATA,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if (null !== $category) {
|
||||
$mutableField = new MutableData($category, $this->stringToBool($node->attr('möglich')));
|
||||
|
||||
if (null !== $until = $node->attr('möglichbiszum')) {
|
||||
$mutableField->mutableBefore = $this->stringToDate($until);
|
||||
}
|
||||
|
||||
$mutableFields[$category] = $mutableField;
|
||||
}
|
||||
})
|
||||
;
|
||||
|
||||
return new BaseData($mutableFields);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user