1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Badcow Common tools. |
4
|
|
|
* |
5
|
|
|
* (c) Samuel Williams <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Badcow\Common; |
12
|
|
|
|
13
|
|
|
class Countries |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Two letter country codes and countries as defined by |
17
|
|
|
* {@link http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2}. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
public static $countryCodes = [ |
22
|
|
|
'AD' => 'Andorra', |
23
|
|
|
'AE' => 'United Arab Emirates', |
24
|
|
|
'AF' => 'Afghanistan', |
25
|
|
|
'AG' => 'Antigua and Barbuda', |
26
|
|
|
'AI' => 'Anguilla', |
27
|
|
|
'AL' => 'Albania', |
28
|
|
|
'AM' => 'Armenia', |
29
|
|
|
'AO' => 'Angola', |
30
|
|
|
'AQ' => 'Antarctica', |
31
|
|
|
'AR' => 'Argentina', |
32
|
|
|
'AS' => 'American Samoa', |
33
|
|
|
'AT' => 'Austria', |
34
|
|
|
'AU' => 'Australia', |
35
|
|
|
'AW' => 'Aruba', |
36
|
|
|
'AX' => 'Åland Islands', |
37
|
|
|
'AZ' => 'Azerbaijan', |
38
|
|
|
'BA' => 'Bosnia and Herzegovina', |
39
|
|
|
'BB' => 'Barbados', |
40
|
|
|
'BD' => 'Bangladesh', |
41
|
|
|
'BE' => 'Belgium', |
42
|
|
|
'BF' => 'Burkina Faso', |
43
|
|
|
'BG' => 'Bulgaria', |
44
|
|
|
'BH' => 'Bahrain', |
45
|
|
|
'BI' => 'Burundi', |
46
|
|
|
'BJ' => 'Benin', |
47
|
|
|
'BL' => 'Saint Barthélemy', |
48
|
|
|
'BM' => 'Bermuda', |
49
|
|
|
'BN' => 'Brunei Darussalam', |
50
|
|
|
'BO' => 'Bolivia, Plurinational State of', |
51
|
|
|
'BQ' => 'Bonaire, Sint Eustatius and Saba', |
52
|
|
|
'BR' => 'Brazil', |
53
|
|
|
'BS' => 'Bahamas', |
54
|
|
|
'BT' => 'Bhutan', |
55
|
|
|
'BV' => 'Bouvet Island', |
56
|
|
|
'BW' => 'Botswana', |
57
|
|
|
'BY' => 'Belarus', |
58
|
|
|
'BZ' => 'Belize', |
59
|
|
|
'CA' => 'Canada', |
60
|
|
|
'CC' => 'Cocos (Keeling) Islands', |
61
|
|
|
'CD' => 'Congo, the Democratic Republic of the', |
62
|
|
|
'CF' => 'Central African Republic', |
63
|
|
|
'CG' => 'Congo', |
64
|
|
|
'CH' => 'Switzerland', |
65
|
|
|
'CI' => 'Côte d\'Ivoire', |
66
|
|
|
'CK' => 'Cook Islands', |
67
|
|
|
'CL' => 'Chile', |
68
|
|
|
'CM' => 'Cameroon', |
69
|
|
|
'CN' => 'China', |
70
|
|
|
'CO' => 'Colombia', |
71
|
|
|
'CR' => 'Costa Rica', |
72
|
|
|
'CU' => 'Cuba', |
73
|
|
|
'CV' => 'Cape Verde', |
74
|
|
|
'CW' => 'Curaçao', |
75
|
|
|
'CX' => 'Christmas Island', |
76
|
|
|
'CY' => 'Cyprus', |
77
|
|
|
'CZ' => 'Czech Republic', |
78
|
|
|
'DE' => 'Germany', |
79
|
|
|
'DJ' => 'Djibouti', |
80
|
|
|
'DK' => 'Denmark', |
81
|
|
|
'DM' => 'Dominica', |
82
|
|
|
'DO' => 'Dominican Republic', |
83
|
|
|
'DZ' => 'Algeria', |
84
|
|
|
'EC' => 'Ecuador', |
85
|
|
|
'EE' => 'Estonia', |
86
|
|
|
'EG' => 'Egypt', |
87
|
|
|
'EH' => 'Western Sahara', |
88
|
|
|
'ER' => 'Eritrea', |
89
|
|
|
'ES' => 'Spain', |
90
|
|
|
'ET' => 'Ethiopia', |
91
|
|
|
'FI' => 'Finland', |
92
|
|
|
'FJ' => 'Fiji', |
93
|
|
|
'FK' => 'Falkland Islands (Malvinas)', |
94
|
|
|
'FM' => 'Micronesia, Federated States of', |
95
|
|
|
'FO' => 'Faroe Islands', |
96
|
|
|
'FR' => 'France', |
97
|
|
|
'GA' => 'Gabon', |
98
|
|
|
'GB' => 'United Kingdom', |
99
|
|
|
'GD' => 'Grenada', |
100
|
|
|
'GE' => 'Georgia', |
101
|
|
|
'GF' => 'French Guiana', |
102
|
|
|
'GG' => 'Guernsey', |
103
|
|
|
'GH' => 'Ghana', |
104
|
|
|
'GI' => 'Gibraltar', |
105
|
|
|
'GL' => 'Greenland', |
106
|
|
|
'GM' => 'Gambia', |
107
|
|
|
'GN' => 'Guinea', |
108
|
|
|
'GP' => 'Guadeloupe', |
109
|
|
|
'GQ' => 'Equatorial Guinea', |
110
|
|
|
'GR' => 'Greece', |
111
|
|
|
'GS' => 'South Georgia and the South Sandwich Islands', |
112
|
|
|
'GT' => 'Guatemala', |
113
|
|
|
'GU' => 'Guam', |
114
|
|
|
'GW' => 'Guinea-Bissau', |
115
|
|
|
'GY' => 'Guyana', |
116
|
|
|
'HK' => 'Hong Kong', |
117
|
|
|
'HM' => 'Heard Island and McDonald Islands', |
118
|
|
|
'HN' => 'Honduras', |
119
|
|
|
'HR' => 'Croatia', |
120
|
|
|
'HT' => 'Haiti', |
121
|
|
|
'HU' => 'Hungary', |
122
|
|
|
'ID' => 'Indonesia', |
123
|
|
|
'IE' => 'Ireland', |
124
|
|
|
'IL' => 'Israel', |
125
|
|
|
'IM' => 'Isle of Man', |
126
|
|
|
'IN' => 'India', |
127
|
|
|
'IO' => 'British Indian Ocean Territory', |
128
|
|
|
'IQ' => 'Iraq', |
129
|
|
|
'IR' => 'Iran, Islamic Republic of', |
130
|
|
|
'IS' => 'Iceland', |
131
|
|
|
'IT' => 'Italy', |
132
|
|
|
'JE' => 'Jersey', |
133
|
|
|
'JM' => 'Jamaica', |
134
|
|
|
'JO' => 'Jordan', |
135
|
|
|
'JP' => 'Japan', |
136
|
|
|
'KE' => 'Kenya', |
137
|
|
|
'KG' => 'Kyrgyzstan', |
138
|
|
|
'KH' => 'Cambodia', |
139
|
|
|
'KI' => 'Kiribati', |
140
|
|
|
'KM' => 'Comoros', |
141
|
|
|
'KN' => 'Saint Kitts and Nevis', |
142
|
|
|
'KP' => 'Korea, Democratic People\'s Republic of', |
143
|
|
|
'KR' => 'Korea, Republic of', |
144
|
|
|
'KW' => 'Kuwait', |
145
|
|
|
'KY' => 'Cayman Islands', |
146
|
|
|
'KZ' => 'Kazakhstan', |
147
|
|
|
'LA' => 'Lao People\'s Democratic Republic', |
148
|
|
|
'LB' => 'Lebanon', |
149
|
|
|
'LC' => 'Saint Lucia', |
150
|
|
|
'LI' => 'Liechtenstein', |
151
|
|
|
'LK' => 'Sri Lanka', |
152
|
|
|
'LR' => 'Liberia', |
153
|
|
|
'LS' => 'Lesotho', |
154
|
|
|
'LT' => 'Lithuania', |
155
|
|
|
'LU' => 'Luxembourg', |
156
|
|
|
'LV' => 'Latvia', |
157
|
|
|
'LY' => 'Libya', |
158
|
|
|
'MA' => 'Morocco', |
159
|
|
|
'MC' => 'Monaco', |
160
|
|
|
'MD' => 'Moldova, Republic of', |
161
|
|
|
'ME' => 'Montenegro', |
162
|
|
|
'MF' => 'Saint Martin (French part)', |
163
|
|
|
'MG' => 'Madagascar', |
164
|
|
|
'MH' => 'Marshall Islands', |
165
|
|
|
'MK' => 'Macedonia, the former Yugoslav Republic of', |
166
|
|
|
'ML' => 'Mali', |
167
|
|
|
'MM' => 'Myanmar', |
168
|
|
|
'MN' => 'Mongolia', |
169
|
|
|
'MO' => 'Macao', |
170
|
|
|
'MP' => 'Northern Mariana Islands', |
171
|
|
|
'MQ' => 'Martinique', |
172
|
|
|
'MR' => 'Mauritania', |
173
|
|
|
'MS' => 'Montserrat', |
174
|
|
|
'MT' => 'Malta', |
175
|
|
|
'MU' => 'Mauritius', |
176
|
|
|
'MV' => 'Maldives', |
177
|
|
|
'MW' => 'Malawi', |
178
|
|
|
'MX' => 'Mexico', |
179
|
|
|
'MY' => 'Malaysia', |
180
|
|
|
'MZ' => 'Mozambique', |
181
|
|
|
'NA' => 'Namibia', |
182
|
|
|
'NC' => 'New Caledonia', |
183
|
|
|
'NE' => 'Niger', |
184
|
|
|
'NF' => 'Norfolk Island', |
185
|
|
|
'NG' => 'Nigeria', |
186
|
|
|
'NI' => 'Nicaragua', |
187
|
|
|
'NL' => 'Netherlands', |
188
|
|
|
'NO' => 'Norway', |
189
|
|
|
'NP' => 'Nepal', |
190
|
|
|
'NR' => 'Nauru', |
191
|
|
|
'NU' => 'Niue', |
192
|
|
|
'NZ' => 'New Zealand', |
193
|
|
|
'OM' => 'Oman', |
194
|
|
|
'PA' => 'Panama', |
195
|
|
|
'PE' => 'Peru', |
196
|
|
|
'PF' => 'French Polynesia', |
197
|
|
|
'PG' => 'Papua New Guinea', |
198
|
|
|
'PH' => 'Philippines', |
199
|
|
|
'PK' => 'Pakistan', |
200
|
|
|
'PL' => 'Poland', |
201
|
|
|
'PM' => 'Saint Pierre and Miquelon', |
202
|
|
|
'PN' => 'Pitcairn', |
203
|
|
|
'PR' => 'Puerto Rico', |
204
|
|
|
'PS' => 'Palestinian Territory, Occupied', |
205
|
|
|
'PT' => 'Portugal', |
206
|
|
|
'PW' => 'Palau', |
207
|
|
|
'PY' => 'Paraguay', |
208
|
|
|
'QA' => 'Qatar', |
209
|
|
|
'RE' => 'Réunion', |
210
|
|
|
'RO' => 'Romania', |
211
|
|
|
'RS' => 'Serbia', |
212
|
|
|
'RU' => 'Russian Federation', |
213
|
|
|
'RW' => 'Rwanda', |
214
|
|
|
'SA' => 'Saudi Arabia', |
215
|
|
|
'SB' => 'Solomon Islands', |
216
|
|
|
'SC' => 'Seychelles', |
217
|
|
|
'SD' => 'Sudan', |
218
|
|
|
'SE' => 'Sweden', |
219
|
|
|
'SG' => 'Singapore', |
220
|
|
|
'SH' => 'Saint Helena, Ascension and Tristan da Cunha', |
221
|
|
|
'SI' => 'Slovenia', |
222
|
|
|
'SJ' => 'Svalbard and Jan Mayen', |
223
|
|
|
'SK' => 'Slovakia', |
224
|
|
|
'SL' => 'Sierra Leone', |
225
|
|
|
'SM' => 'San Marino', |
226
|
|
|
'SN' => 'Senegal', |
227
|
|
|
'SO' => 'Somalia', |
228
|
|
|
'SR' => 'Suriname', |
229
|
|
|
'SS' => 'South Sudan', |
230
|
|
|
'ST' => 'Sao Tome and Principe', |
231
|
|
|
'SV' => 'El Salvador', |
232
|
|
|
'SX' => 'Sint Maarten (Dutch part)', |
233
|
|
|
'SY' => 'Syrian Arab Republic', |
234
|
|
|
'SZ' => 'Swaziland', |
235
|
|
|
'TC' => 'Turks and Caicos Islands', |
236
|
|
|
'TD' => 'Chad', |
237
|
|
|
'TF' => 'French Southern Territories', |
238
|
|
|
'TG' => 'Togo', |
239
|
|
|
'TH' => 'Thailand', |
240
|
|
|
'TJ' => 'Tajikistan', |
241
|
|
|
'TK' => 'Tokelau', |
242
|
|
|
'TL' => 'Timor-Leste', |
243
|
|
|
'TM' => 'Turkmenistan', |
244
|
|
|
'TN' => 'Tunisia', |
245
|
|
|
'TO' => 'Tonga', |
246
|
|
|
'TR' => 'Turkey', |
247
|
|
|
'TT' => 'Trinidad and Tobago', |
248
|
|
|
'TV' => 'Tuvalu', |
249
|
|
|
'TW' => 'Taiwan, Province of China', |
250
|
|
|
'TZ' => 'Tanzania, United Republic of', |
251
|
|
|
'UA' => 'Ukraine', |
252
|
|
|
'UG' => 'Uganda', |
253
|
|
|
'UM' => 'United States Minor Outlying Islands', |
254
|
|
|
'US' => 'United States', |
255
|
|
|
'UY' => 'Uruguay', |
256
|
|
|
'UZ' => 'Uzbekistan', |
257
|
|
|
'VA' => 'Holy See (Vatican City State)', |
258
|
|
|
'VC' => 'Saint Vincent and the Grenadines', |
259
|
|
|
'VE' => 'Venezuela, Bolivarian Republic of', |
260
|
|
|
'VG' => 'Virgin Islands, British', |
261
|
|
|
'VI' => 'Virgin Islands, U.S.', |
262
|
|
|
'VN' => 'Viet Nam', |
263
|
|
|
'VU' => 'Vanuatu', |
264
|
|
|
'WF' => 'Wallis and Futuna', |
265
|
|
|
'WS' => 'Samoa', |
266
|
|
|
'YE' => 'Yemen', |
267
|
|
|
'YT' => 'Mayotte', |
268
|
|
|
'ZA' => 'South Africa', |
269
|
|
|
'ZM' => 'Zambia', |
270
|
|
|
'ZW' => 'Zimbabwe', |
271
|
|
|
]; |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Verify if the country code is valid. |
275
|
|
|
* |
276
|
|
|
* @param string $countryCode |
277
|
|
|
* @return bool |
278
|
|
|
*/ |
279
|
6 |
|
public static function isValid($countryCode) |
280
|
|
|
{ |
281
|
6 |
|
return array_key_exists($countryCode, self::$countryCodes); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Get a country name given a country code |
286
|
|
|
* |
287
|
|
|
* @param string $countryCode |
288
|
|
|
* @return null |
289
|
|
|
*/ |
290
|
3 |
|
public static function getCountryName($countryCode) |
291
|
|
|
{ |
292
|
3 |
|
if (self::isValid($countryCode)) { |
293
|
3 |
|
return self::$countryCodes[$countryCode]; |
294
|
|
|
} |
295
|
|
|
|
296
|
3 |
|
return null; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|