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,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Model\Surcharge;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class SurchargesParser extends AbstractParser
|
||||
{
|
||||
public function parse(Crawler $result): array
|
||||
{
|
||||
$surcharges = [];
|
||||
|
||||
$result->each(function (Crawler $node) use (&$surcharges) {
|
||||
$surcharge = new Surcharge();
|
||||
$surchargeLabel = $node->attr('bezeichnung');
|
||||
$surcharge->label = empty($surchargeLabel) ? 'unbekannt' : $surchargeLabel;
|
||||
$surcharge->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$surcharge->mapping = array_map('intval', $mapping);
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$surcharge->individualPrice = array_combine($mapping, $individualPrices);
|
||||
|
||||
$surcharges[] = $surcharge;
|
||||
});
|
||||
|
||||
return $surcharges;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user