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