feat: refactoring of xml parsers

This commit is contained in:
Björn Fromme
2025-01-24 17:10:49 +01:00
parent 11f1508640
commit 6730c243f6
49 changed files with 1414 additions and 1235 deletions
@@ -0,0 +1,70 @@
<?php
namespace App\BusProNet\XmlParser;
use App\BusProNet\Model\Address;
use App\BusProNet\Model\Communication;
use App\BusProNet\Model\PersonalData;
use Symfony\Component\DomCrawler\Crawler;
use voku\helper\AntiXSS;
class PersonalDataParser extends AbstractParser
{
public function parse(Crawler $node): PersonalData
{
$personalData = new PersonalData();
$personalData->addressId = $this->getIntOrNullValue($node->filterXPath('//idadresse'));
$personalData->personId = $this->getIntOrNullValue($node->filterXPath('//idperson'));
$addressDataNode = $node->filterXPath('//adressdaten');
$dateString = $this->getStringOrNullValue($addressDataNode->filterXPath('//geburtsdatum'));
$personalData->dateOfBirth = null !== $dateString ?
\DateTimeImmutable::createFromFormat('d.m.Y', $dateString) : null;
$personalData->firstName = $this->getStringOrNullValue($addressDataNode->filterXPath('//vorname'));
$personalData->name = $this->getStringOrNullValue($addressDataNode->filterXPath('//name'));
$personalData->salutation = $this->getStringOrNullValue($addressDataNode->filterXPath('//anrede'));
$personalData->title = $this->getStringOrNullValue($addressDataNode->filterXPath('//titel'));
$personalData->gender = strtoupper($this->getStringOrNullValue($addressDataNode->filterXPath('//geschlecht')));
$personalData->height = $this->getStringOrNullValue($addressDataNode->filterXPath('//sonstiges1'));
$personalData->weight = $this->getStringOrNullValue($addressDataNode->filterXPath('//sonstiges2'));
$personalData->shoeSize = $this->getStringOrNullValue($addressDataNode->filterXPath('//sonstiges3'));
$addressNode = $addressDataNode->filterXPath('//anschrift');
if (0 < $addressNode->count()) {
$address = new Address();
$address->street = $this->getStringOrNullValue($addressNode->filterXPath('//strasse'));
$address->postCode = $this->getStringOrNullValue($addressNode->filterXPath('//plz'));
$address->city = $this->getStringOrNullValue($addressNode->filterXPath('//ort')) ;
$address->country = $this->getStringOrNullValue($addressNode->filterXPath('//land')) ;
$personalData->address = $address;
}
$contactDataNode = $addressDataNode->filterXPath('//kommunikation');
if (0 < $contactDataNode->count()) {
$communication = new Communication();
$communication->phone = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonprivat'));
$communication->mobile = $this->getStringOrNullValue($contactDataNode->filterXPath('//telefonmobil'));
$communication->email = $this->getStringOrNullValue($contactDataNode->filterXPath('//email'));
$communication->newsletter = $this
->stringToBool($this->getStringOrNullValue($contactDataNode->filterXPath('//newsletter')));
$personalData->communication = $communication;
}
$remarksNode = $addressDataNode->filterXPath('//bemerkung');
if (0 < $remarksNode->count()) {
$antiXss = new AntiXSS();
$personalData->remarks = $antiXss->xss_clean($remarksNode->text());
}
return $personalData;
}
}