|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace h4kuna\Exchange\Nette; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime, |
|
6
|
|
|
h4kuna\Exchange\Currency, |
|
7
|
|
|
h4kuna\Exchange\Storage, |
|
8
|
|
|
Nette\Caching; |
|
9
|
|
|
|
|
10
|
|
|
final class Cache extends Caching\Cache implements Storage\IStock |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** @var string represent time */ |
|
14
|
|
|
private $refresh = '15:30'; |
|
15
|
|
|
|
|
16
|
|
|
/** @return DateTime */ |
|
17
|
|
|
private function getRefresh() |
|
18
|
|
|
{ |
|
19
|
|
|
if (is_string($this->refresh)) { |
|
20
|
|
|
$this->refresh = new DateTime('today ' . $this->refresh); |
|
|
|
|
|
|
21
|
|
|
if (new DateTime >= $this->refresh) { |
|
22
|
|
|
$this->refresh->modify('+1 day'); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
return $this->refresh; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $hour |
|
30
|
|
|
* @return Storage |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setRefresh($hour) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->refresh = $hour; |
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Currency\IProperty $currency |
|
40
|
|
|
*/ |
|
41
|
|
|
public function saveCurrency(Currency\IProperty $currency) |
|
42
|
|
|
{ |
|
43
|
|
|
$refresh = $this->getRefresh(); |
|
44
|
|
|
$expire = NULL; |
|
45
|
|
|
if ($refresh) { |
|
46
|
|
|
$expire = [self::EXPIRE => $refresh]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->save($currency->getCode(), $currency, $expire); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $currencies |
|
54
|
|
|
*/ |
|
55
|
|
|
public function saveCurrencies(array $currencies) |
|
56
|
|
|
{ |
|
57
|
|
|
foreach ($currencies as $currency) { |
|
58
|
|
|
$this->saveCurrency($currency); |
|
59
|
|
|
} |
|
60
|
|
|
$this->save(self::ALL_CURRENCIES, array_keys($currencies)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function loadCurrency($code) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->load($code); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** @return array */ |
|
69
|
|
|
public function getListCurrencies() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->loadCurrency(self::ALL_CURRENCIES); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** Nette 2.4 interface fix **/ |
|
75
|
|
|
|
|
76
|
|
|
public function offsetSet($key, $data) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->save($key, $data); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function offsetGet($key) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->load($key); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function offsetExists($key) |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->load($key); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function offsetUnset($key) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->remove($key); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..