mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 06:42:22 +02:00
Update list of Country Codes
To update the list of countries, I decided to use the iso-codes [1] instead of GeoNames [2] as it seems like that one is more often updated. This commit will also create a Bash script to update that list in the future. [1]: https://salsa.debian.org/iso-codes-team/iso-codes [2]: http://www.geonames.org/ Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
9b810b0e55
commit
f580e187d0
55
bin/update-iso-codes
Executable file
55
bin/update-iso-codes
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
# Usage: {script} TLD_FILENAME
|
||||
# Update list of TLD
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
declare -r IFS=$'\n'
|
||||
declare -r REPOSITORY_URL="https://salsa.debian.org/iso-codes-team/iso-codes.git"
|
||||
declare -r REPOSITORY_DIRECTORY=$(mktemp --directory)
|
||||
declare -r LIBRARY_DIRECTORY="${1}"
|
||||
|
||||
clone_repository()
|
||||
{
|
||||
echo "Cloning repository ${REPOSITORY_URL}"
|
||||
git clone --quiet "${REPOSITORY_URL}" "${REPOSITORY_DIRECTORY}"
|
||||
}
|
||||
|
||||
list_iso_3166()
|
||||
{
|
||||
local -r number_of_items=${1}
|
||||
local -r filename=${2}
|
||||
|
||||
for index in $(seq 0 ${number_of_items}); do
|
||||
local json=$(jq ".[][${index}]" < "${filename}")
|
||||
local alpha_2=$(jq ".alpha_2" <<< "${json}" | tr '"' "'")
|
||||
local alpha_3=$(jq ".alpha_3" <<< "${json}" | tr '"' "'")
|
||||
local numeric=$(jq ".numeric" <<< "${json}" | tr '"' "'")
|
||||
local name=$(jq -r ".name" <<< "${json}")
|
||||
echo " [${alpha_2}, ${alpha_3}, ${numeric}], // ${name}"
|
||||
done
|
||||
}
|
||||
|
||||
update_country_codes()
|
||||
{
|
||||
local -r iso_3166_1_filename="${REPOSITORY_DIRECTORY}/data/iso_3166-1.json"
|
||||
local -r iso_3166_1_count=$(grep "alpha_3" "${iso_3166_1_filename}" | wc --lines)
|
||||
local -r iso_3166_3_filename="${REPOSITORY_DIRECTORY}/data/iso_3166-3.json"
|
||||
local -r iso_3166_3_count=$(grep "alpha_3" "${iso_3166_3_filename}" | wc --lines)
|
||||
local -r temporary_filename=$(mktemp)
|
||||
local -r country_rule_filename="${LIBRARY_DIRECTORY}/Rules/CountryCode.php"
|
||||
|
||||
echo "Updating country codes using ISO 3166-1 and ISO 3166-3"
|
||||
{
|
||||
sed -n '/^</,/ protected/p' "${country_rule_filename}"
|
||||
{
|
||||
list_iso_3166 $[iso_3166_1_count - 1] ${iso_3166_1_filename}
|
||||
list_iso_3166 $[iso_3166_3_count - 1] ${iso_3166_3_filename}
|
||||
} | sort
|
||||
sed -n '/^ ]/,/^}/p' "${country_rule_filename}"
|
||||
} > "${temporary_filename}"
|
||||
mv "${temporary_filename}" "${country_rule_filename}"
|
||||
}
|
||||
|
||||
clone_repository
|
||||
update_country_codes
|
|
@ -8,6 +8,8 @@ Validates an ISO country code like US or BR.
|
|||
v::countryCode()->validate('BR'); // true
|
||||
```
|
||||
|
||||
This rules uses data from [iso-codes][].
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
|
@ -16,3 +18,6 @@ See also:
|
|||
* [PostalCode](PostalCode.md)
|
||||
* [SubdivisionCode](SubdivisionCode.md)
|
||||
* [Tld](Tld.md)
|
||||
|
||||
|
||||
[iso-codes]: https://salsa.debian.org/iso-codes-team/iso-codes
|
||||
|
|
|
@ -23,7 +23,7 @@ class CountryCode extends AbstractRule
|
|||
const NUMERIC = 'numeric';
|
||||
|
||||
/**
|
||||
* @link http://download.geonames.org/export/dump/countryInfo.txt
|
||||
* @link https://salsa.debian.org/iso-codes-team/iso-codes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@ class CountryCode extends AbstractRule
|
|||
['AE', 'ARE', '784'], // United Arab Emirates
|
||||
['AF', 'AFG', '004'], // Afghanistan
|
||||
['AG', 'ATG', '028'], // Antigua and Barbuda
|
||||
['AI', 'AFI', '262'], // French Afars and Issas
|
||||
['AI', 'AIA', '660'], // Anguilla
|
||||
['AL', 'ALB', '008'], // Albania
|
||||
['AM', 'ARM', '051'], // Armenia
|
||||
|
@ -43,7 +44,7 @@ class CountryCode extends AbstractRule
|
|||
['AT', 'AUT', '040'], // Austria
|
||||
['AU', 'AUS', '036'], // Australia
|
||||
['AW', 'ABW', '533'], // Aruba
|
||||
['AX', 'ALA', '248'], // Aland Islands
|
||||
['AX', 'ALA', '248'], // Åland Islands
|
||||
['AZ', 'AZE', '031'], // Azerbaijan
|
||||
['BA', 'BIH', '070'], // Bosnia and Herzegovina
|
||||
['BB', 'BRB', '052'], // Barbados
|
||||
|
@ -54,43 +55,50 @@ class CountryCode extends AbstractRule
|
|||
['BH', 'BHR', '048'], // Bahrain
|
||||
['BI', 'BDI', '108'], // Burundi
|
||||
['BJ', 'BEN', '204'], // Benin
|
||||
['BL', 'BLM', '652'], // Saint Barthelemy
|
||||
['BL', 'BLM', '652'], // Saint Barthélemy
|
||||
['BM', 'BMU', '060'], // Bermuda
|
||||
['BN', 'BRN', '096'], // Brunei
|
||||
['BO', 'BOL', '068'], // Bolivia
|
||||
['BQ', 'BES', '535'], // Bonaire, Saint Eustatius and Saba
|
||||
['BN', 'BRN', '096'], // Brunei Darussalam
|
||||
['BO', 'BOL', '068'], // Bolivia, Plurinational State of
|
||||
['BQ', 'ATB', null], // British Antarctic Territory
|
||||
['BQ', 'BES', '535'], // Bonaire, Sint Eustatius and Saba
|
||||
['BR', 'BRA', '076'], // Brazil
|
||||
['BS', 'BHS', '044'], // Bahamas
|
||||
['BT', 'BTN', '064'], // Bhutan
|
||||
['BU', 'BUR', '104'], // Burma, Socialist Republic of the Union of
|
||||
['BV', 'BVT', '074'], // Bouvet Island
|
||||
['BW', 'BWA', '072'], // Botswana
|
||||
['BY', 'BLR', '112'], // Belarus
|
||||
['BY', 'BYS', '112'], // Byelorussian SSR Soviet Socialist Republic
|
||||
['BZ', 'BLZ', '084'], // Belize
|
||||
['CA', 'CAN', '124'], // Canada
|
||||
['CC', 'CCK', '166'], // Cocos Islands
|
||||
['CD', 'COD', '180'], // Democratic Republic of the Congo
|
||||
['CC', 'CCK', '166'], // Cocos (Keeling) Islands
|
||||
['CD', 'COD', '180'], // Congo, The Democratic Republic of the
|
||||
['CF', 'CAF', '140'], // Central African Republic
|
||||
['CG', 'COG', '178'], // Republic of the Congo
|
||||
['CG', 'COG', '178'], // Congo
|
||||
['CH', 'CHE', '756'], // Switzerland
|
||||
['CI', 'CIV', '384'], // Ivory Coast
|
||||
['CI', 'CIV', '384'], // Côte d'Ivoire
|
||||
['CK', 'COK', '184'], // Cook Islands
|
||||
['CL', 'CHL', '152'], // Chile
|
||||
['CM', 'CMR', '120'], // Cameroon
|
||||
['CN', 'CHN', '156'], // China
|
||||
['CO', 'COL', '170'], // Colombia
|
||||
['CR', 'CRI', '188'], // Costa Rica
|
||||
['CS', 'CSK', '200'], // Czechoslovakia, Czechoslovak Socialist Republic
|
||||
['CS', 'SCG', '891'], // Serbia and Montenegro
|
||||
['CT', 'CTE', '128'], // Canton and Enderbury Islands
|
||||
['CU', 'CUB', '192'], // Cuba
|
||||
['CV', 'CPV', '132'], // Cape Verde
|
||||
['CW', 'CUW', '531'], // Curacao
|
||||
['CV', 'CPV', '132'], // Cabo Verde
|
||||
['CW', 'CUW', '531'], // Curaçao
|
||||
['CX', 'CXR', '162'], // Christmas Island
|
||||
['CY', 'CYP', '196'], // Cyprus
|
||||
['CZ', 'CZE', '203'], // Czech Republic
|
||||
['CZ', 'CZE', '203'], // Czechia
|
||||
['DD', 'DDR', '278'], // German Democratic Republic
|
||||
['DE', 'DEU', '276'], // Germany
|
||||
['DJ', 'DJI', '262'], // Djibouti
|
||||
['DK', 'DNK', '208'], // Denmark
|
||||
['DM', 'DMA', '212'], // Dominica
|
||||
['DO', 'DOM', '214'], // Dominican Republic
|
||||
['DY', 'DHY', '204'], // Dahomey
|
||||
['DZ', 'DZA', '012'], // Algeria
|
||||
['EC', 'ECU', '218'], // Ecuador
|
||||
['EE', 'EST', '233'], // Estonia
|
||||
|
@ -101,13 +109,16 @@ class CountryCode extends AbstractRule
|
|||
['ET', 'ETH', '231'], // Ethiopia
|
||||
['FI', 'FIN', '246'], // Finland
|
||||
['FJ', 'FJI', '242'], // Fiji
|
||||
['FK', 'FLK', '238'], // Falkland Islands
|
||||
['FM', 'FSM', '583'], // Micronesia
|
||||
['FK', 'FLK', '238'], // Falkland Islands (Malvinas)
|
||||
['FM', 'FSM', '583'], // Micronesia, Federated States of
|
||||
['FO', 'FRO', '234'], // Faroe Islands
|
||||
['FQ', 'ATF', null], // French Southern and Antarctic Territories
|
||||
['FR', 'FRA', '250'], // France
|
||||
['FX', 'FXX', '249'], // France, Metropolitan
|
||||
['GA', 'GAB', '266'], // Gabon
|
||||
['GB', 'GBR', '826'], // United Kingdom
|
||||
['GD', 'GRD', '308'], // Grenada
|
||||
['GE', 'GEL', '296'], // Gilbert and Ellice Islands
|
||||
['GE', 'GEO', '268'], // Georgia
|
||||
['GF', 'GUF', '254'], // French Guiana
|
||||
['GG', 'GGY', '831'], // Guernsey
|
||||
|
@ -130,6 +141,7 @@ class CountryCode extends AbstractRule
|
|||
['HR', 'HRV', '191'], // Croatia
|
||||
['HT', 'HTI', '332'], // Haiti
|
||||
['HU', 'HUN', '348'], // Hungary
|
||||
['HV', 'HVO', '854'], // Upper Volta, Republic of
|
||||
['ID', 'IDN', '360'], // Indonesia
|
||||
['IE', 'IRL', '372'], // Ireland
|
||||
['IL', 'ISR', '376'], // Israel
|
||||
|
@ -137,25 +149,26 @@ class CountryCode extends AbstractRule
|
|||
['IN', 'IND', '356'], // India
|
||||
['IO', 'IOT', '086'], // British Indian Ocean Territory
|
||||
['IQ', 'IRQ', '368'], // Iraq
|
||||
['IR', 'IRN', '364'], // Iran
|
||||
['IR', 'IRN', '364'], // Iran, Islamic Republic of
|
||||
['IS', 'ISL', '352'], // Iceland
|
||||
['IT', 'ITA', '380'], // Italy
|
||||
['JE', 'JEY', '832'], // Jersey
|
||||
['JM', 'JAM', '388'], // Jamaica
|
||||
['JO', 'JOR', '400'], // Jordan
|
||||
['JP', 'JPN', '392'], // Japan
|
||||
['JT', 'JTN', '396'], // Johnston Island
|
||||
['KE', 'KEN', '404'], // Kenya
|
||||
['KG', 'KGZ', '417'], // Kyrgyzstan
|
||||
['KH', 'KHM', '116'], // Cambodia
|
||||
['KI', 'KIR', '296'], // Kiribati
|
||||
['KM', 'COM', '174'], // Comoros
|
||||
['KN', 'KNA', '659'], // Saint Kitts and Nevis
|
||||
['KP', 'PRK', '408'], // North Korea
|
||||
['KR', 'KOR', '410'], // South Korea
|
||||
['KP', 'PRK', '408'], // Korea, Democratic People's Republic of
|
||||
['KR', 'KOR', '410'], // Korea, Republic of
|
||||
['KW', 'KWT', '414'], // Kuwait
|
||||
['KY', 'CYM', '136'], // Cayman Islands
|
||||
['KZ', 'KAZ', '398'], // Kazakhstan
|
||||
['LA', 'LAO', '418'], // Laos
|
||||
['LA', 'LAO', '418'], // Lao People's Democratic Republic
|
||||
['LB', 'LBN', '422'], // Lebanon
|
||||
['LC', 'LCA', '662'], // Saint Lucia
|
||||
['LI', 'LIE', '438'], // Liechtenstein
|
||||
|
@ -168,12 +181,13 @@ class CountryCode extends AbstractRule
|
|||
['LY', 'LBY', '434'], // Libya
|
||||
['MA', 'MAR', '504'], // Morocco
|
||||
['MC', 'MCO', '492'], // Monaco
|
||||
['MD', 'MDA', '498'], // Moldova
|
||||
['MD', 'MDA', '498'], // Moldova, Republic of
|
||||
['ME', 'MNE', '499'], // Montenegro
|
||||
['MF', 'MAF', '663'], // Saint Martin
|
||||
['MF', 'MAF', '663'], // Saint Martin (French part)
|
||||
['MG', 'MDG', '450'], // Madagascar
|
||||
['MH', 'MHL', '584'], // Marshall Islands
|
||||
['MK', 'MKD', '807'], // Macedonia
|
||||
['MI', 'MID', '488'], // Midway Islands
|
||||
['MK', 'MKD', '807'], // North Macedonia
|
||||
['ML', 'MLI', '466'], // Mali
|
||||
['MM', 'MMR', '104'], // Myanmar
|
||||
['MN', 'MNG', '496'], // Mongolia
|
||||
|
@ -194,15 +208,19 @@ class CountryCode extends AbstractRule
|
|||
['NE', 'NER', '562'], // Niger
|
||||
['NF', 'NFK', '574'], // Norfolk Island
|
||||
['NG', 'NGA', '566'], // Nigeria
|
||||
['NH', 'NHB', '548'], // New Hebrides
|
||||
['NI', 'NIC', '558'], // Nicaragua
|
||||
['NL', 'NLD', '528'], // Netherlands
|
||||
['NO', 'NOR', '578'], // Norway
|
||||
['NP', 'NPL', '524'], // Nepal
|
||||
['NQ', 'ATN', '216'], // Dronning Maud Land
|
||||
['NR', 'NRU', '520'], // Nauru
|
||||
['NT', 'NTZ', '536'], // Neutral Zone
|
||||
['NU', 'NIU', '570'], // Niue
|
||||
['NZ', 'NZL', '554'], // New Zealand
|
||||
['OM', 'OMN', '512'], // Oman
|
||||
['PA', 'PAN', '591'], // Panama
|
||||
['PC', 'PCI', '582'], // Pacific Islands (trust territory)
|
||||
['PE', 'PER', '604'], // Peru
|
||||
['PF', 'PYF', '258'], // French Polynesia
|
||||
['PG', 'PNG', '598'], // Papua New Guinea
|
||||
|
@ -212,15 +230,18 @@ class CountryCode extends AbstractRule
|
|||
['PM', 'SPM', '666'], // Saint Pierre and Miquelon
|
||||
['PN', 'PCN', '612'], // Pitcairn
|
||||
['PR', 'PRI', '630'], // Puerto Rico
|
||||
['PS', 'PSE', '275'], // Palestinian Territory
|
||||
['PS', 'PSE', '275'], // Palestine, State of
|
||||
['PT', 'PRT', '620'], // Portugal
|
||||
['PU', 'PUS', '849'], // US Miscellaneous Pacific Islands
|
||||
['PW', 'PLW', '585'], // Palau
|
||||
['PY', 'PRY', '600'], // Paraguay
|
||||
['PZ', 'PCZ', null], // Panama Canal Zone
|
||||
['QA', 'QAT', '634'], // Qatar
|
||||
['RE', 'REU', '638'], // Reunion
|
||||
['RE', 'REU', '638'], // Réunion
|
||||
['RH', 'RHO', '716'], // Southern Rhodesia
|
||||
['RO', 'ROU', '642'], // Romania
|
||||
['RS', 'SRB', '688'], // Serbia
|
||||
['RU', 'RUS', '643'], // Russia
|
||||
['RU', 'RUS', '643'], // Russian Federation
|
||||
['RW', 'RWA', '646'], // Rwanda
|
||||
['SA', 'SAU', '682'], // Saudi Arabia
|
||||
['SB', 'SLB', '090'], // Solomon Islands
|
||||
|
@ -228,9 +249,10 @@ class CountryCode extends AbstractRule
|
|||
['SD', 'SDN', '729'], // Sudan
|
||||
['SE', 'SWE', '752'], // Sweden
|
||||
['SG', 'SGP', '702'], // Singapore
|
||||
['SH', 'SHN', '654'], // Saint Helena
|
||||
['SH', 'SHN', '654'], // Saint Helena, Ascension and Tristan da Cunha
|
||||
['SI', 'SVN', '705'], // Slovenia
|
||||
['SJ', 'SJM', '744'], // Svalbard and Jan Mayen
|
||||
['SK', 'SKM', null], // Sikkim
|
||||
['SK', 'SVK', '703'], // Slovakia
|
||||
['SL', 'SLE', '694'], // Sierra Leone
|
||||
['SM', 'SMR', '674'], // San Marino
|
||||
|
@ -239,10 +261,11 @@ class CountryCode extends AbstractRule
|
|||
['SR', 'SUR', '740'], // Suriname
|
||||
['SS', 'SSD', '728'], // South Sudan
|
||||
['ST', 'STP', '678'], // Sao Tome and Principe
|
||||
['SU', 'SUN', '810'], // USSR, Union of Soviet Socialist Republics
|
||||
['SV', 'SLV', '222'], // El Salvador
|
||||
['SX', 'SXM', '534'], // Sint Maarten
|
||||
['SY', 'SYR', '760'], // Syria
|
||||
['SZ', 'SWZ', '748'], // Swaziland
|
||||
['SX', 'SXM', '534'], // Sint Maarten (Dutch part)
|
||||
['SY', 'SYR', '760'], // Syrian Arab Republic
|
||||
['SZ', 'SWZ', '748'], // Eswatini
|
||||
['TC', 'TCA', '796'], // Turks and Caicos Islands
|
||||
['TD', 'TCD', '148'], // Chad
|
||||
['TF', 'ATF', '260'], // French Southern Territories
|
||||
|
@ -250,37 +273,41 @@ class CountryCode extends AbstractRule
|
|||
['TH', 'THA', '764'], // Thailand
|
||||
['TJ', 'TJK', '762'], // Tajikistan
|
||||
['TK', 'TKL', '772'], // Tokelau
|
||||
['TL', 'TLS', '626'], // East Timor
|
||||
['TL', 'TLS', '626'], // Timor-Leste
|
||||
['TM', 'TKM', '795'], // Turkmenistan
|
||||
['TN', 'TUN', '788'], // Tunisia
|
||||
['TO', 'TON', '776'], // Tonga
|
||||
['TP', 'TMP', '626'], // East Timor
|
||||
['TR', 'TUR', '792'], // Turkey
|
||||
['TT', 'TTO', '780'], // Trinidad and Tobago
|
||||
['TV', 'TUV', '798'], // Tuvalu
|
||||
['TW', 'TWN', '158'], // Taiwan
|
||||
['TZ', 'TZA', '834'], // Tanzania
|
||||
['TW', 'TWN', '158'], // Taiwan, Province of China
|
||||
['TZ', 'TZA', '834'], // Tanzania, United Republic of
|
||||
['UA', 'UKR', '804'], // Ukraine
|
||||
['UG', 'UGA', '800'], // Uganda
|
||||
['UM', 'UMI', '581'], // United States Minor Outlying Islands
|
||||
['US', 'USA', '840'], // United States
|
||||
['UY', 'URY', '858'], // Uruguay
|
||||
['UZ', 'UZB', '860'], // Uzbekistan
|
||||
['VA', 'VAT', '336'], // Vatican
|
||||
['VA', 'VAT', '336'], // Holy See (Vatican City State)
|
||||
['VC', 'VCT', '670'], // Saint Vincent and the Grenadines
|
||||
['VE', 'VEN', '862'], // Venezuela
|
||||
['VG', 'VGB', '092'], // British Virgin Islands
|
||||
['VI', 'VIR', '850'], // U.S. Virgin Islands
|
||||
['VN', 'VNM', '704'], // Vietnam
|
||||
['VD', 'VDR', null], // Viet-Nam, Democratic Republic of
|
||||
['VE', 'VEN', '862'], // Venezuela, Bolivarian Republic of
|
||||
['VG', 'VGB', '092'], // Virgin Islands, British
|
||||
['VI', 'VIR', '850'], // Virgin Islands, U.S.
|
||||
['VN', 'VNM', '704'], // Viet Nam
|
||||
['VU', 'VUT', '548'], // Vanuatu
|
||||
['WF', 'WLF', '876'], // Wallis and Futuna
|
||||
['WK', 'WAK', '872'], // Wake Island
|
||||
['WS', 'WSM', '882'], // Samoa
|
||||
['XK', 'XKX', '0'], // Kosovo
|
||||
['YD', 'YMD', '720'], // Yemen, Democratic, People's Democratic Republic of
|
||||
['YE', 'YEM', '887'], // Yemen
|
||||
['YT', 'MYT', '175'], // Mayotte
|
||||
['YU', 'YUG', '891'], // Yugoslavia, Socialist Federal Republic of
|
||||
['ZA', 'ZAF', '710'], // South Africa
|
||||
['ZM', 'ZMB', '894'], // Zambia
|
||||
['ZR', 'ZAR', '180'], // Zaire, Republic of
|
||||
['ZW', 'ZWE', '716'], // Zimbabwe
|
||||
|
||||
];
|
||||
|
||||
public $set;
|
||||
|
|
Loading…
Reference in a new issue