1 | <?php |
||
31 | class Manager implements ManagerInterface |
||
32 | { |
||
33 | use LoggerAwareTrait; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $baseCurrency; |
||
39 | |||
40 | /** |
||
41 | * @var RepositoryInterface |
||
42 | */ |
||
43 | protected $repository; |
||
44 | |||
45 | /** |
||
46 | * @var SourcesRegistryInterface |
||
47 | */ |
||
48 | protected $sources; |
||
49 | |||
50 | /** |
||
51 | * @var ProcessorsRegistryInterface |
||
52 | */ |
||
53 | protected $processors; |
||
54 | |||
55 | /** |
||
56 | * @var RatesConfigurationRegistryInterface |
||
57 | */ |
||
58 | protected $configurations; |
||
59 | |||
60 | 8 | public function __construct($baseCurrency, RepositoryInterface $repository, SourcesRegistryInterface $sources, ProcessorsRegistryInterface $processors, RatesConfigurationRegistryInterface $configurations) |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 6 | public function has($sourceName, $currencyCode, $date = null, $rateType = 'default') |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 2 | public function get($sourceName, $currencyCode, $date = null, $rateType = 'default') |
|
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 2 | public function latest($sourceName, $currencyCode, $rateType = 'default') |
|
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | 4 | public function today($sourceName, $currencyCode, $rateType = 'default') |
|
97 | { |
||
98 | 4 | $currencyCode = CurrencyCodeUtil::clean($currencyCode); |
|
99 | 4 | $today = new \DateTime('now'); |
|
100 | |||
101 | 4 | if ($this->has($sourceName, $currencyCode, $today, $rateType)) { |
|
102 | return $this->get($sourceName, $currencyCode, $today, $rateType); |
||
103 | } |
||
104 | |||
105 | 4 | if ((int)$today->format('N') >= 6) { |
|
106 | |||
107 | $today = new \DateTime('last Friday'); |
||
108 | |||
109 | try { |
||
110 | return $this->get($sourceName, $currencyCode, $today, $rateType); |
||
111 | } catch (\Exception $e) { |
||
112 | $message = sprintf('Rate for currency code "%s" of type "%s" from source "%s" is not available for today "%s".', $currencyCode, $rateType, $sourceName, date('Y-m-d')); |
||
113 | $this->getLogger()->critical($message); |
||
114 | throw new ExchangeRateException($message, 0, $e); |
||
115 | } |
||
116 | } |
||
117 | 4 | } |
|
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | 2 | public function fetch($sourceName = null, $date = null) |
|
155 | } |
||
156 |