WIP: Implement even more stuff

This commit is contained in:
Björn Fromme committed 2023-10-04 17:54:35 +02:00
1 parent cc1ab396af
commit 96d6170907
31 files changed
+874 -68

No files matched your search

@@ -0,0 +1,39 @@
<?php
namespace App\BusProNet\DataProvider;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\Pickup;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
class PickupDataProvider
{
public function __construct(private readonly ApiClient $apiClient, private readonly CacheInterface $cache)
{}
public function getAll(): array
{
try {
$pickups = $this->cache->get('bpn_pickups', function (ItemInterface $item) {
$item->expiresAfter(3600);
return $this
->apiClient
->getBaseData(ApiClient::TYPE_BASE_DATA_PICKUPS)
->getItems()
;
});
} catch (ApiClientException $e) {
$pickups = [];
}
return $pickups;
}
public function get(int $busProId): ?Pickup
{
return $this->getAll()[$busProId] ?? null;
}
}