1 | <?php |
||
12 | class EcbClient implements EcbClientInterface |
||
13 | { |
||
14 | /** |
||
15 | * @const string |
||
16 | */ |
||
17 | const DEFAULT_EXCHANGE_RATES_URL = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; |
||
18 | |||
19 | /** |
||
20 | * @const int |
||
21 | */ |
||
22 | const CACHE_UNTIL_MIDNIGHT = -1; |
||
23 | |||
24 | /** |
||
25 | * @var Client |
||
26 | */ |
||
27 | private $client; |
||
28 | |||
29 | /** |
||
30 | * @var CacheInterface |
||
31 | */ |
||
32 | private $cache; |
||
33 | |||
34 | /** |
||
35 | * @var int |
||
36 | */ |
||
37 | private $cacheTimeInSeconds; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $exchangeRatesUrl; |
||
43 | |||
44 | /** |
||
45 | * @param string $exchangeRatesUrl |
||
46 | * @param CacheInterface $cache |
||
47 | * @param int $cacheTimeInSeconds -1 to cache until midnight |
||
48 | */ |
||
49 | public function __construct(string $exchangeRatesUrl = self::DEFAULT_EXCHANGE_RATES_URL, CacheInterface $cache = null, int $cacheTimeInSeconds = self::CACHE_UNTIL_MIDNIGHT) |
||
56 | |||
57 | /** |
||
58 | * @throws ExchangeRatesRequestFailedException |
||
59 | * @return ExchangeRate[] |
||
60 | */ |
||
61 | public function getExchangeRates(): array |
||
76 | |||
77 | /** |
||
78 | * @return Response |
||
79 | */ |
||
80 | private function performCachedRequest() |
||
98 | |||
99 | /** |
||
100 | * @return Response |
||
101 | */ |
||
102 | private function performRequest() |
||
107 | |||
108 | } |
||
109 |