1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate package, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\ExchangeRate\Utils; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\ExchangeRate\Exception\UnknownCurrencyCodeException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class CurrencyCodeUtil |
16
|
|
|
* |
17
|
|
|
* Currency code utilities. |
18
|
|
|
* |
19
|
|
|
* @package RunOpenCode\ExchangeRate\Utils |
20
|
|
|
*/ |
21
|
|
|
final class CurrencyCodeUtil |
22
|
|
|
{ |
23
|
|
|
private function __construct() |
24
|
|
|
{ |
25
|
|
|
// noop |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* List of currency codes. |
30
|
|
|
* |
31
|
|
|
* List of currency codes. List contains some of already obsolete currency codes as well. |
32
|
|
|
* |
33
|
|
|
* @see https://gist.github.com/Min2liz/5728013 |
34
|
|
|
* @see https://en.wikipedia.org/wiki/ISO_4217 |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $codes = array( |
39
|
|
|
'ALL' => 'Albania Lek', |
40
|
|
|
'AFN' => 'Afghanistan Afghani', |
41
|
|
|
'ARS' => 'Argentina Peso', |
42
|
|
|
'AWG' => 'Aruba Guilder', |
43
|
|
|
'AUD' => 'Australia Dollar', |
44
|
|
|
'AZN' => 'Azerbaijan New Manat', |
45
|
|
|
'BSD' => 'Bahamas Dollar', |
46
|
|
|
'BBD' => 'Barbados Dollar', |
47
|
|
|
'BDT' => 'Bangladeshi taka', |
48
|
|
|
'BYR' => 'Belarus Ruble', |
49
|
|
|
'BZD' => 'Belize Dollar', |
50
|
|
|
'BMD' => 'Bermuda Dollar', |
51
|
|
|
'BOB' => 'Bolivia Boliviano', |
52
|
|
|
'BAM' => 'Bosnia and Herzegovina Convertible Marka', |
53
|
|
|
'BWP' => 'Botswana Pula', |
54
|
|
|
'BGN' => 'Bulgaria Lev', |
55
|
|
|
'BRL' => 'Brazil Real', |
56
|
|
|
'BND' => 'Brunei Darussalam Dollar', |
57
|
|
|
'KHR' => 'Cambodia Riel', |
58
|
|
|
'CAD' => 'Canada Dollar', |
59
|
|
|
'KYD' => 'Cayman Islands Dollar', |
60
|
|
|
'CLP' => 'Chile Peso', |
61
|
|
|
'CNY' => 'China Yuan Renminbi', |
62
|
|
|
'COP' => 'Colombia Peso', |
63
|
|
|
'CRC' => 'Costa Rica Colon', |
64
|
|
|
'HRK' => 'Croatia Kuna', |
65
|
|
|
'CUP' => 'Cuba Peso', |
66
|
|
|
'CZK' => 'Czech Republic Koruna', |
67
|
|
|
'DKK' => 'Denmark Krone', |
68
|
|
|
'DOP' => 'Dominican Republic Peso', |
69
|
|
|
'XCD' => 'East Caribbean Dollar', |
70
|
|
|
'EGP' => 'Egypt Pound', |
71
|
|
|
'SVC' => 'El Salvador Colon', |
72
|
|
|
'EEK' => 'Estonia Kroon', |
73
|
|
|
'EUR' => 'Euro Member Countries', |
74
|
|
|
'FKP' => 'Falkland Islands (Malvinas) Pound', |
75
|
|
|
'FJD' => 'Fiji Dollar', |
76
|
|
|
'GHC' => 'Ghana Cedis', |
77
|
|
|
'GIP' => 'Gibraltar Pound', |
78
|
|
|
'GTQ' => 'Guatemala Quetzal', |
79
|
|
|
'GGP' => 'Guernsey Pound', |
80
|
|
|
'GYD' => 'Guyana Dollar', |
81
|
|
|
'HNL' => 'Honduras Lempira', |
82
|
|
|
'HKD' => 'Hong Kong Dollar', |
83
|
|
|
'HUF' => 'Hungary Forint', |
84
|
|
|
'ISK' => 'Iceland Krona', |
85
|
|
|
'INR' => 'India Rupee', |
86
|
|
|
'IDR' => 'Indonesia Rupiah', |
87
|
|
|
'IRR' => 'Iran Rial', |
88
|
|
|
'IMP' => 'Isle of Man Pound', |
89
|
|
|
'ILS' => 'Israel Shekel', |
90
|
|
|
'JMD' => 'Jamaica Dollar', |
91
|
|
|
'JPY' => 'Japan Yen', |
92
|
|
|
'JEP' => 'Jersey Pound', |
93
|
|
|
'KZT' => 'Kazakhstan Tenge', |
94
|
|
|
'KPW' => 'Korea (North) Won', |
95
|
|
|
'KRW' => 'Korea (South) Won', |
96
|
|
|
'KGS' => 'Kyrgyzstan Som', |
97
|
|
|
'LAK' => 'Laos Kip', |
98
|
|
|
'LVL' => 'Latvia Lat', |
99
|
|
|
'LBP' => 'Lebanon Pound', |
100
|
|
|
'LRD' => 'Liberia Dollar', |
101
|
|
|
'LTL' => 'Lithuania Litas', |
102
|
|
|
'MKD' => 'Macedonia Denar', |
103
|
|
|
'MYR' => 'Malaysia Ringgit', |
104
|
|
|
'MUR' => 'Mauritius Rupee', |
105
|
|
|
'MXN' => 'Mexico Peso', |
106
|
|
|
'MNT' => 'Mongolia Tughrik', |
107
|
|
|
'MZN' => 'Mozambique Metical', |
108
|
|
|
'NAD' => 'Namibia Dollar', |
109
|
|
|
'NPR' => 'Nepal Rupee', |
110
|
|
|
'ANG' => 'Netherlands Antilles Guilder', |
111
|
|
|
'NZD' => 'New Zealand Dollar', |
112
|
|
|
'NIO' => 'Nicaragua Cordoba', |
113
|
|
|
'NGN' => 'Nigeria Naira', |
114
|
|
|
'NOK' => 'Norway Krone', |
115
|
|
|
'OMR' => 'Oman Rial', |
116
|
|
|
'PKR' => 'Pakistan Rupee', |
117
|
|
|
'PAB' => 'Panama Balboa', |
118
|
|
|
'PYG' => 'Paraguay Guarani', |
119
|
|
|
'PEN' => 'Peru Nuevo Sol', |
120
|
|
|
'PHP' => 'Philippines Peso', |
121
|
|
|
'PLN' => 'Poland Zloty', |
122
|
|
|
'QAR' => 'Qatar Riyal', |
123
|
|
|
'RON' => 'Romania New Leu', |
124
|
|
|
'RUB' => 'Russia Ruble', |
125
|
|
|
'SHP' => 'Saint Helena Pound', |
126
|
|
|
'SAR' => 'Saudi Arabia Riyal', |
127
|
|
|
'RSD' => 'Serbia Dinar', |
128
|
|
|
'SCR' => 'Seychelles Rupee', |
129
|
|
|
'SGD' => 'Singapore Dollar', |
130
|
|
|
'SBD' => 'Solomon Islands Dollar', |
131
|
|
|
'SOS' => 'Somalia Shilling', |
132
|
|
|
'ZAR' => 'South Africa Rand', |
133
|
|
|
'LKR' => 'Sri Lanka Rupee', |
134
|
|
|
'SEK' => 'Sweden Krona', |
135
|
|
|
'CHF' => 'Switzerland Franc', |
136
|
|
|
'SRD' => 'Suriname Dollar', |
137
|
|
|
'SYP' => 'Syria Pound', |
138
|
|
|
'TWD' => 'Taiwan New Dollar', |
139
|
|
|
'THB' => 'Thailand Baht', |
140
|
|
|
'TTD' => 'Trinidad and Tobago Dollar', |
141
|
|
|
'TRY' => 'Turkey Lira', |
142
|
|
|
'TRL' => 'Turkey Lira', |
143
|
|
|
'TVD' => 'Tuvalu Dollar', |
144
|
|
|
'UAH' => 'Ukraine Hryvna', |
145
|
|
|
'GBP' => 'United Kingdom Pound', |
146
|
|
|
'UGX' => 'Uganda Shilling', |
147
|
|
|
'USD' => 'United States Dollar', |
148
|
|
|
'UYU' => 'Uruguay Peso', |
149
|
|
|
'UZS' => 'Uzbekistan Som', |
150
|
|
|
'VEF' => 'Venezuela Bolivar', |
151
|
|
|
'VND' => 'Viet Nam Dong', |
152
|
|
|
'YER' => 'Yemen Rial', |
153
|
|
|
'ZWD' => 'Zimbabwe Dollar', |
154
|
|
|
'KWD' => 'Kuwait Dinar', |
155
|
|
|
'ATS' => 'Austrian Schilling', |
156
|
|
|
'BEF' => 'Belgian Franc', |
157
|
|
|
'FIM' => 'Finnish Markka', |
158
|
|
|
'FRF' => 'French Franc', |
159
|
|
|
'DEM' => 'German Mark', |
160
|
|
|
'GRD' => 'Greece Drachma', |
161
|
|
|
'IEP' => 'Ireland Pound', |
162
|
|
|
'ITL' => 'Italy Lira', |
163
|
|
|
'LUF' => 'Luxembourg Franc', |
164
|
|
|
'PTE' => 'Portugal Escudo', |
165
|
|
|
'ESP' => 'Spain Peseta', |
166
|
|
|
'XDR' => 'IMF Special Drawing Rights', |
167
|
|
|
'SKK' => 'Slovak Koruna', |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Check if currency code exists. |
172
|
|
|
* |
173
|
|
|
* @param string $currencyCode ISO 4271 currency code. |
174
|
|
|
* @return bool TRUE if exists. |
175
|
|
|
*/ |
176
|
25 |
|
public static function exists($currencyCode) |
177
|
|
|
{ |
178
|
25 |
|
$currencyCode = trim(strtoupper($currencyCode)); |
179
|
|
|
|
180
|
25 |
|
return array_key_exists($currencyCode, self::$codes); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Clean currency code |
185
|
|
|
* |
186
|
|
|
* @param string $currencyCode Currency code to clean up. |
187
|
|
|
* @return string Cleaned ISO 4271 currency code. |
188
|
|
|
* @throws UnknownCurrencyCodeException If currency code does not exists. |
189
|
|
|
*/ |
190
|
23 |
|
public static function clean($currencyCode) |
191
|
|
|
{ |
192
|
23 |
|
$clean = trim(strtoupper($currencyCode)); |
193
|
|
|
|
194
|
23 |
|
if (!self::exists($clean)) { |
195
|
1 |
|
throw new UnknownCurrencyCodeException(sprintf('Unknown currency code "%s".', $currencyCode)); |
196
|
|
|
} |
197
|
|
|
|
198
|
22 |
|
return $clean; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|