1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate package, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* Implementation of exchange rate crawler for National Bank of Serbia, http://www.nbs.rs. |
6
|
|
|
* |
7
|
|
|
* (c) 2017 RunOpenCode |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace RunOpenCode\ExchangeRate\NationalBankOfSerbia; |
13
|
|
|
|
14
|
|
|
use RunOpenCode\ExchangeRate\NationalBankOfSerbia\Enum\RateType; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Api |
18
|
|
|
* |
19
|
|
|
* Api definition of National Bank of Serbia crawler. |
20
|
|
|
* |
21
|
|
|
* @package RunOpenCode\ExchangeRate\NationalBankOfSerbia |
22
|
|
|
*/ |
23
|
|
|
final class Api |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Unique name of source. |
27
|
|
|
*/ |
28
|
|
|
const NAME = 'national_bank_of_serbia'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Supported rate types and currency codes by National Bank of Serbia. |
32
|
|
|
* |
33
|
|
|
* NOTE: National Bank of Serbia still publishes rates of some of the obsolete currencies. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private static $supports = array( |
38
|
|
|
RateType::MEDIAN => array('EUR', 'AUD', 'CAD', 'CNY', 'HRK', 'CZK', 'DKK', 'HUF', 'JPY', 'KWD', 'NOK', 'RUB', 'SEK', 'CHF', |
39
|
|
|
'GBP', 'USD', 'BAM', 'PLN', 'ATS', 'BEF', 'FIM', 'FRF', 'DEM', 'GRD', 'IEP', 'ITL', 'LUF', 'PTE', |
40
|
|
|
'ESP', 'BYN'), |
41
|
|
|
RateType::FOREIGN_CASH_BUYING => array('EUR', 'CHF', 'USD'), |
42
|
|
|
RateType::FOREIGN_CASH_SELLING => array('EUR', 'CHF', 'USD'), |
43
|
|
|
RateType::FOREIGN_EXCHANGE_BUYING => array('EUR', 'AUD', 'CAD', 'CNY', 'DKK', 'JPY', 'NOK', 'RUB', 'SEK', 'CHF', 'GBP', 'USD', 'BYN'), |
44
|
|
|
RateType::FOREIGN_EXCHANGE_SELLING => array('EUR', 'AUD', 'CAD', 'CNY', 'DKK', 'JPY', 'NOK', 'RUB', 'SEK', 'CHF', 'GBP', 'USD', 'BYN'), |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
private function __construct() { /* noop */ } |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Check if National Bank of Serbia supports given exchange rate currency code for given rate type. |
51
|
|
|
* |
52
|
|
|
* @param string $currencyCode Currency code. |
53
|
|
|
* @param string $rateType Rate type. |
54
|
|
|
* @return bool TRUE if currency code within rate type is supported. |
55
|
|
|
*/ |
56
|
7 |
|
public static function supports($currencyCode, $rateType) |
57
|
|
|
{ |
58
|
|
|
if ( |
59
|
7 |
|
!array_key_exists($rateType, self::$supports) |
60
|
|
|
|| |
61
|
6 |
|
!in_array($currencyCode, self::$supports[$rateType], true) |
62
|
|
|
) { |
63
|
1 |
|
return false; |
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
return true; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|