1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VojtaSvoboda\CnbRates\Facades; |
4
|
|
|
|
5
|
|
|
use Event; |
6
|
|
|
use VojtaSvoboda\CnbRates\Services\ExchangeRateService; |
7
|
|
|
use VojtaSvoboda\CnbRates\Services\PriborService; |
8
|
|
|
|
9
|
|
|
class CnbFacade |
10
|
|
|
{ |
11
|
|
|
private $exchangeRateService; |
12
|
|
|
|
13
|
|
|
private $priborService; |
14
|
|
|
|
15
|
9 |
|
public function __construct(ExchangeRateService $exchanges, PriborService $pribors) |
16
|
|
|
{ |
17
|
9 |
|
$this->exchangeRateService = $exchanges; |
18
|
9 |
|
$this->priborService = $pribors; |
19
|
9 |
|
} |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
//--- Exchange Services |
23
|
|
|
|
24
|
|
|
|
25
|
3 |
|
public function getExchangeRates($date = null) |
26
|
|
|
{ |
27
|
3 |
|
return $this->exchangeRateService->getExchangeRates($date); |
28
|
|
|
} |
29
|
|
|
|
30
|
1 |
|
public function updateTodayExchangeRates() |
31
|
|
|
{ |
32
|
1 |
|
$rates = $this->getExchangeRates(); |
33
|
|
|
|
34
|
1 |
|
Event::fire('vojtasvoboda.cnbrates.exchange.updated', [$rates]); |
35
|
|
|
|
36
|
1 |
|
return $rates; |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
public function getExchangeRate($currency = 'CZK', $date = null) |
40
|
|
|
{ |
41
|
2 |
|
return $this->exchangeRateService->getExchangeRate($currency, $date); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
//--- PRIBOR Services |
46
|
|
|
|
47
|
|
|
|
48
|
3 |
|
public function getPriborRates($date = null) |
49
|
|
|
{ |
50
|
3 |
|
return $this->priborService->getPriborRates($date); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
public function updateTodayPriborRates() |
54
|
|
|
{ |
55
|
1 |
|
$rates = $this->getPriborRates(); |
56
|
|
|
|
57
|
1 |
|
Event::fire('vojtasvoboda.cnbrates.pribor.updated', [$rates]); |
58
|
|
|
|
59
|
1 |
|
return $rates; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function getPriborRate($date = null, $interval = 'year') |
63
|
|
|
{ |
64
|
1 |
|
return $this->priborService->getPriborRate($date, $interval); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
//--- PRIBOR shortcuts |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function getPriborRateForYear($date = null) |
72
|
|
|
{ |
73
|
|
|
return $this->getPriborRate($date, 'year'); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function getPriborRateFor9Months($date = null) |
77
|
|
|
{ |
78
|
1 |
|
return $this->getPriborRate($date, '9months'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getPriborRateFor6Months($date = null) |
82
|
|
|
{ |
83
|
|
|
return $this->getPriborRate($date, '6months'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getPriborRateFor3Months($date = null) |
87
|
|
|
{ |
88
|
|
|
return $this->getPriborRate($date, '3months'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getPriborRateFor2Months($date = null) |
92
|
|
|
{ |
93
|
|
|
return $this->getPriborRate($date, '2months'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getPriborRateForMonth($date = null) |
97
|
|
|
{ |
98
|
|
|
return $this->getPriborRate($date, 'month'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getPriborRateFor2Weeks($date = null) |
102
|
|
|
{ |
103
|
|
|
return $this->getPriborRate($date, '2weeks'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getPriborRateForWeek($date = null) |
107
|
|
|
{ |
108
|
|
|
return $this->getPriborRate($date, 'week'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getPriborRateForDay($date = null) |
112
|
|
|
{ |
113
|
|
|
return $this->getPriborRate($date, 'day'); |
114
|
|
|
} |
115
|
|
|
} |