wip: initial commit

This commit is contained in:
Björn Fromme committed 2024-11-20 18:32:09 +01:00
1 parent ae964198e9
commit d4c4e69d09
91 files changed
+32685 -144

No files matched your search

@@ -0,0 +1,42 @@
<?php
namespace App\BusProNet\DataProvider;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\Country;
use Psr\Cache\InvalidArgumentException;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
class CountryDataProvider
{
public function __construct(private readonly ApiClient $apiClient, private readonly CacheInterface $cache)
{}
public function getAll(): array
{
try {
return $this->cache->get('bpn_countries', function (ItemInterface $item) {
$item->expiresAfter(3600);
return $this
->apiClient
->getBaseData(ApiClient::TYPE_BASE_DATA_COUNTRIES)
->getItems()
;
});
} catch (InvalidArgumentException $e) {
return [];
}
}
public function get(?string $token): ?Country
{
if (null === $token) {
return null;
}
return $this->getAll()[$token] ?? null;
}
}