feat: integrate with flysystem for xml data
This commit is contained in:
1 parent
036734eadf
commit
e4e03a848b
12 files changed
+617
-24
No files matched your search
@@ -11,9 +11,10 @@ use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
@@ -23,9 +24,9 @@ class TravelLoader extends AbstractLoader
|
||||
private readonly HotelLoader $hotelDataLoader,
|
||||
CacheInterface $cache,
|
||||
private readonly string $travelInfoBaseUrl,
|
||||
?string $xmlPath = null
|
||||
FileSystemOperator $xmlExport,
|
||||
) {
|
||||
parent::__construct($cache, $xmlPath);
|
||||
parent::__construct($cache, $xmlExport);
|
||||
}
|
||||
|
||||
public function generateFilesMap(): array
|
||||
@@ -34,14 +35,21 @@ class TravelLoader extends AbstractLoader
|
||||
return $this->cache->get('bpn_travels_mapping', function (ItemInterface $item) {
|
||||
$item->expiresAfter(3 * 60 * 60);
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->files()->in($this->xmlPath)->name('Ziel_*.xml');
|
||||
$xmlFiles = $this
|
||||
->xmlExport
|
||||
->listContents('.')->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
|
||||
;
|
||||
|
||||
$mapping = [];
|
||||
$hotels = $this->hotelDataLoader->loadAll();
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$xml = $file->getContents();
|
||||
foreach ($xmlFiles as $file) {
|
||||
if (false === str_starts_with($file->path(), 'Ziel_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$xml = $this->xmlExport->read($file->path());
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$travelDataNodes = $crawler->filterXPath('//reisen/reise/termin');
|
||||
|
||||
@@ -55,7 +63,7 @@ class TravelLoader extends AbstractLoader
|
||||
'dateFrom' => $this->stringToDate($node->attr('termin')),
|
||||
'dateTo' => $this->stringToDate($node->attr('bis')),
|
||||
'hotels' => [],
|
||||
'file' => $file->getRealPath(),
|
||||
'file' => $file->path(),
|
||||
];
|
||||
|
||||
$node->filterXPath('//hotel')
|
||||
@@ -110,7 +118,7 @@ class TravelLoader extends AbstractLoader
|
||||
|
||||
private function loadXml(int $id, ?int $hotelId, string $filename): ?Travel
|
||||
{
|
||||
$xml = file_get_contents($filename);
|
||||
$xml = $this->xmlExport->read($filename);
|
||||
$crawler = new Crawler($xml);
|
||||
|
||||
$travelNode = $crawler->filterXPath(sprintf('//reise/termin[@idbuspro="%d"]', $id));
|
||||
|
||||
Reference in new issue
Block a user