1 | <?php namespace Arcanedev\Currencies\Bases; |
||
17 | abstract class AbstractService implements CurrencyService |
||
18 | { |
||
19 | /* ------------------------------------------------------------------------------------------------ |
||
20 | | Properties |
||
21 | | ------------------------------------------------------------------------------------------------ |
||
22 | */ |
||
23 | /** |
||
24 | * The currency manager instance. |
||
25 | * |
||
26 | * @var \Arcanedev\Currencies\Contracts\CurrencyManager |
||
27 | */ |
||
28 | protected $manager; |
||
29 | |||
30 | /** |
||
31 | * The cache repository. |
||
32 | * |
||
33 | * @var \Illuminate\Contracts\Cache\Repository |
||
34 | */ |
||
35 | protected $cache; |
||
36 | |||
37 | /** |
||
38 | * The enabled cache status. |
||
39 | * |
||
40 | * @var bool |
||
41 | */ |
||
42 | protected $cacheEnabled; |
||
43 | |||
44 | /** |
||
45 | * The cache key name. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $cacheKey; |
||
50 | |||
51 | /** |
||
52 | * The cache duration. |
||
53 | * |
||
54 | * @var int |
||
55 | */ |
||
56 | protected $cacheDuration; |
||
57 | |||
58 | /* ------------------------------------------------------------------------------------------------ |
||
59 | | Constructor |
||
60 | | ------------------------------------------------------------------------------------------------ |
||
61 | */ |
||
62 | /** |
||
63 | * AbstractApiService constructor. |
||
64 | * |
||
65 | * @param \Arcanedev\Currencies\Contracts\CurrencyManager $manager |
||
66 | * @param \Illuminate\Contracts\Cache\Repository $cache |
||
67 | * @param array $configs |
||
68 | */ |
||
69 | 120 | public function __construct( |
|
79 | |||
80 | /* ------------------------------------------------------------------------------------------------ |
||
81 | | Getters & Setters |
||
82 | | ------------------------------------------------------------------------------------------------ |
||
83 | */ |
||
84 | /** |
||
85 | * Set the configs. |
||
86 | * |
||
87 | * @param array $configs |
||
88 | */ |
||
89 | abstract protected function setConfigs(array $configs); |
||
90 | |||
91 | /** |
||
92 | * Set the cache configs. |
||
93 | * |
||
94 | * @param array $configs |
||
95 | */ |
||
96 | 120 | protected function setCacheConfigs(array $configs) |
|
102 | |||
103 | /** |
||
104 | * Get the default currency. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 60 | public function getDefault() |
|
112 | |||
113 | /** |
||
114 | * Get the supported currencies. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | 24 | public function getSupported() |
|
122 | |||
123 | /** |
||
124 | * Get the `from` currency. |
||
125 | * |
||
126 | * @param string|null $from |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 48 | protected function getFromCurrency($from = null) |
|
134 | |||
135 | /** |
||
136 | * Get the `to` currencies. |
||
137 | * |
||
138 | * @param array|string|null $to |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | protected function getToCurrencies($to = null) |
||
150 | |||
151 | /** |
||
152 | * Get cache key. |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | protected function getCacheKey() |
||
160 | |||
161 | /** |
||
162 | * Check if cache is enabled. |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | 48 | protected function isCacheEnabled() |
|
170 | |||
171 | /* ------------------------------------------------------------------------------------------------ |
||
172 | | Main Functions |
||
173 | | ------------------------------------------------------------------------------------------------ |
||
174 | */ |
||
175 | /** |
||
176 | * Get supported currencies rates. |
||
177 | * |
||
178 | * @return \Arcanedev\Currencies\Entities\RateCollection |
||
179 | */ |
||
180 | 24 | public function supportedRates() |
|
190 | |||
191 | /* ------------------------------------------------------------------------------------------------ |
||
192 | | Other Functions |
||
193 | | ------------------------------------------------------------------------------------------------ |
||
194 | */ |
||
195 | /** |
||
196 | * Cache results. |
||
197 | * |
||
198 | * @param \Closure $callback |
||
199 | * |
||
200 | * @return array |
||
201 | */ |
||
202 | protected function cacheResults(Closure $callback) |
||
210 | |||
211 | /** |
||
212 | * Prepare rates collection. |
||
213 | * |
||
214 | * @param string $from |
||
215 | * @param array $rates |
||
216 | * |
||
217 | * @return \Arcanedev\Currencies\Entities\RateCollection |
||
218 | */ |
||
219 | 60 | protected function makeRatesCollection($from, array $rates) |
|
223 | } |
||
224 |