From 50807f21ab61a31510b8ba20c0908b11201d7576 Mon Sep 17 00:00:00 2001 From: umpirsky Date: Fri, 2 Mar 2012 15:36:29 +0100 Subject: [PATCH] Implemented json, yaml, PHP and MySQL dumpers. --- .gitmodules | 15 ++ LICENSE | 19 ++ README.md | 4 + autoload.php | 21 ++ build | 29 ++ country/country.af.yaml~ | 255 ++++++++++++++++++ vendor/Symfony/Component/ClassLoader | 1 + vendor/Symfony/Component/Filesystem | 1 + vendor/Symfony/Component/Finder | 1 + vendor/Symfony/Component/Locale | 1 + vendor/Symfony/Component/Yaml | 1 + vendor/Umpirsky/Country/Dumper/Dumper.php | 34 +++ .../Country/Dumper/DumperInterface.php | 28 ++ .../Umpirsky/Country/Dumper/Format/Json.php | 30 +++ .../Umpirsky/Country/Dumper/Format/MySql.php | 48 ++++ vendor/Umpirsky/Country/Dumper/Format/Php.php | 30 +++ .../Umpirsky/Country/Dumper/Format/Yaml.php | 31 +++ vendor/Umpirsky/Country/Dumper/Iterator.php | 67 +++++ 18 files changed, 616 insertions(+) create mode 100644 .gitmodules create mode 100644 LICENSE create mode 100644 autoload.php create mode 100644 build create mode 100644 country/country.af.yaml~ create mode 160000 vendor/Symfony/Component/ClassLoader create mode 160000 vendor/Symfony/Component/Filesystem create mode 160000 vendor/Symfony/Component/Finder create mode 160000 vendor/Symfony/Component/Locale create mode 160000 vendor/Symfony/Component/Yaml create mode 100644 vendor/Umpirsky/Country/Dumper/Dumper.php create mode 100644 vendor/Umpirsky/Country/Dumper/DumperInterface.php create mode 100644 vendor/Umpirsky/Country/Dumper/Format/Json.php create mode 100644 vendor/Umpirsky/Country/Dumper/Format/MySql.php create mode 100644 vendor/Umpirsky/Country/Dumper/Format/Php.php create mode 100644 vendor/Umpirsky/Country/Dumper/Format/Yaml.php create mode 100644 vendor/Umpirsky/Country/Dumper/Iterator.php diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..edf8d9ce9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,15 @@ +[submodule "vendor/Symfony/Component/Locale"] + path = vendor/Symfony/Component/Locale + url = https://github.com/symfony/Locale.git +[submodule "vendor/Symfony/Component/Yaml"] + path = vendor/Symfony/Component/Yaml + url = https://github.com/symfony/Yaml.git +[submodule "vendor/Symfony/Component/ClassLoader"] + path = vendor/Symfony/Component/ClassLoader + url = https://github.com/symfony/ClassLoader.git +[submodule "vendor/Symfony/Component/Filesystem"] + path = vendor/Symfony/Component/Filesystem + url = https://github.com/symfony/Filesystem.git +[submodule "vendor/Symfony/Component/Finder"] + path = vendor/Symfony/Component/Finder + url = https://github.com/symfony/Finder.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..df9dd1073 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) Саша Стаменковић + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index e69de29bb..c3369e0e0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ +Country List +============ + +List of all countries with names and ISO 3166-1 codes in all languages and data formats. \ No newline at end of file diff --git a/autoload.php b/autoload.php new file mode 100644 index 000000000..dcc630c54 --- /dev/null +++ b/autoload.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once __DIR__ . '/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php'; + +use Symfony\Component\ClassLoader\UniversalClassLoader; + +$loader = new UniversalClassLoader(); +$loader->registerNamespaces(array( + 'Symfony' => __DIR__ . '/vendor', + 'Umpirsky' => __DIR__ . '/vendor' +)); +$loader->register(); \ No newline at end of file diff --git a/build b/build new file mode 100644 index 000000000..7e1662261 --- /dev/null +++ b/build @@ -0,0 +1,29 @@ +#!/usr/bin/env php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once __DIR__ . '/autoload.php'; + +use Symfony\Component\Locale\Locale; +use Symfony\Component\Filesystem\Filesystem; +use Umpirsky\Country\Dumper\Iterator; + +$locale = new Locale(); +$filesystem = new Filesystem(); +$dumperIterator = new Iterator(); +foreach ($locale->getLocales() as $language) { + $countries = $locale->getDisplayCountries($language); + foreach($dumperIterator as $dumper) { + $file = sprintf('%s/country/country.%s.%s', __DIR__, $language, $dumper->getFormat()); + $filesystem->touch($file); + file_put_contents($file, $dumper->dump($countries)); + } +} diff --git a/country/country.af.yaml~ b/country/country.af.yaml~ new file mode 100644 index 000000000..758d01c2d --- /dev/null +++ b/country/country.af.yaml~ @@ -0,0 +1,255 @@ +AF: Afganistan +AX: 'Åland Islands' +AL: Albanië +DZ: Algerië +AS: 'Amerikaans Samoa' +AD: Andorra +AO: Angola +AI: Anguilla +AQ: Antarktika +AG: 'Antigua en Barbuda' +AR: Argentinië +AM: Armenië +AW: Aruba +AC: 'Ascension Island' +AZ: Aserbeidjan +AU: Australië +BS: Bahamas +BH: Bahrein +BD: Bangladesj +BB: Barbados +BE: België +BZ: Belize +BJ: Benin +BM: Bermuda +BT: Bhoetan +BF: 'Boerkina Fasso' +BO: Bolivië +BA: 'Bosnië en Herzegowina' +BW: Botswana +BV: 'Bouvet Island' +BR: Brasilië +IO: 'Britse Indiese Oseaan Gebied' +VG: 'Britse Maagde-eilande' +BN: Broenei +BG: Bulgarye +BI: Burundi +IC: 'Canary Islands' +EA: 'Ceuta and Melilla' +CL: Chili +CX: 'Christmas Island' +CY: Ciprus +CP: 'Clipperton Island' +CC: 'Cocos [Keeling] Islands' +KM: Comore +CK: Cookeilande +CR: 'Costa Rica' +CD: 'Demokratiese Republiek van die Kongo' +DK: Denemarke +DG: 'Diego Garcia' +DJ: Djiboeti +DM: Dominika +DO: 'Dominikaanse Republiek' +DE: Duitsland +EC: Ecuador +EG: Egipte +GQ: Ekwatoriaal-Guinee +ER: Eritrea +EE: Estland +ET: Ethiopië +EU: 'European Union' +FK: Falklandeilande +FO: Faroëreilande +FJ: Fidji +PH: Filippyne +FI: Finland +FR: Frankryk +GF: Frans-Guyana +PF: Frans-Polinesië +TF: 'French Southern Territories' +GA: Gaboen +GM: Gambië +GE: Georgië +GH: Ghana +GI: Gibraltar +GD: Grenada +GR: Griekeland +GL: Groenland +GB: Groot-Brittanje +GP: Guadeloupe +GU: Guam +GT: Guatemala +GG: Guernsey +GN: Guinee +GW: Guinee-Bissau +GY: Guyana +HT: Haïti +HM: 'Heard Island and McDonald Islands' +HN: Honduras +HU: Hongarye +HK: Hongkong +IE: Ierland +IN: Indië +ID: Indonesië +IQ: Irak +IR: Iran +IM: 'Isle of Man' +IL: Israel +IT: Italië +CI: Ivoorkus +JM: Jamaika +JP: Japan +YE: Jemen +JE: Jersey +JO: Jordanië +KY: Kaaimanseilande +CV: 'Kaap Verde' +KH: Kambodja +CM: Kameroen +CA: Kanada +KZ: Kasakstan +QA: Katar +KE: Kenia +KG: Kirgisië +KI: Kiribati +KW: Koeweit +CO: Kolombië +CG: Kongo +HR: Kroasië +CU: Kuba +LA: Laos +LS: Lesotho +LV: Letland +LB: Libanon +LR: Liberië +LY: Libië +LI: Liechtenstein +LT: Litaue +LU: Luxemburg +MO: 'Macau SAR China' +MK: Macedonië +MG: Madagaskar +MW: Malawi +MV: Maledive +MY: Maleisië +ML: Mali +MT: Malta +MA: Marokko +MH: Marshall-eilande +MQ: Martinique +MU: Mauritius +YT: Mayotte +MX: Meksiko +MM: Mianmar +FM: Mikronesië +MD: Moldova +MC: Monaco +MN: Mongolië +ME: Montenegro +MS: Montserrat +MZ: Mosambiek +MR: Mouritanië +NA: Namibië +NR: Naoeroe +NL: Nederland +AN: Nederlands-Antille +NP: Nepal +NI: Nicaragua +NC: Nieu-Kaledonië +NZ: Nieu-Seeland +NE: Niger +NG: Nigerië +NU: Niue +KP: Noord-Korea +MP: 'Noordelike Marianaeilande' +NO: Noorweë +NF: Norfolk-eiland +UA: Oekraine +UZ: Oesbekistan +OM: Oman +TL: Oos-Timor +AT: Oostenryk +QO: 'Outlying Oceania' +PK: Pakistan +PW: Palau +PS: Palestina +PA: Panama +PG: 'Papoea Nieu-Guinee' +PY: Paraguay +PE: Peru +PN: Pitcairn +PL: Pole +PT: Portugal +PR: 'Puerto Rico' +RE: Réunion +RO: Roemenië +RU: Rusland +RW: Rwanda +BL: 'Saint Barthélemy' +KN: 'Saint Kitts en Nevis' +MF: 'Saint Martin' +VC: 'Saint Vincent en die Grenadine' +SV: Salvador +WS: Samoa +SM: 'San Marino' +ST: 'Sao Tome en Principe' +SA: Saoedi-Arabië +SN: Senegal +CF: 'Sentraal-Afrikaanse Republiek' +RS: Serbia +CS: 'Serwië en Montenegro' +SC: Seychelle +SL: 'Sierra Leone' +SG: Singapoer +SH: 'Sint Helena' +LC: 'Sint Lucia' +PM: 'Sint-Pierre en Miquelon' +SY: Sirië +CN: Sjina +SK: Slowakye +SI: Slowenië +SD: Soedan +SB: 'Solomon Eilande' +SO: Somalië +GS: 'South Georgia and the South Sandwich Islands' +ES: Spanje +LK: 'Sri Lanka' +ZA: Suid-Afrika +KR: Suid-Korea +SR: Suriname +SJ: 'Svalbard and Jan Mayen' +SZ: Swaziland +SE: Swede +CH: Switserland +TJ: Tadjikistan +TW: Taiwan +TZ: Tanzanië +TH: Thailand +CZ: 'Tjeggiese Republiek' +TG: Togo +TK: Tokelau +TO: Tonga +TT: 'Trinidad en Tobago' +TA: 'Tristan da Cunha' +TD: Tsjaad +TN: Tunisië +TM: Turkmenië +TC: 'Turks en Caicos Eilande' +TR: Turkye +TV: Tuvalu +UM: 'U.S. Minor Outlying Islands' +UG: Uganda +UY: Uruguay +VI: 'V.S. Maagde-eilande' +VU: Vanuatu +VA: Vatikaan +VE: Venezuela +AE: 'Verenigde Arabiese Emirate' +US: 'Verenigde State van Amerika' +VN: Viëtnam +WF: 'Wallis en Futuna' +EH: Wes-Sahara +BY: Wit-Rusland +IS: Ysland +ZM: Zambië +ZW: Zimbabwe diff --git a/vendor/Symfony/Component/ClassLoader b/vendor/Symfony/Component/ClassLoader new file mode 160000 index 000000000..8bceaa2f1 --- /dev/null +++ b/vendor/Symfony/Component/ClassLoader @@ -0,0 +1 @@ +Subproject commit 8bceaa2f1fed52f6285b2cea39e7ae37fbea1c9b diff --git a/vendor/Symfony/Component/Filesystem b/vendor/Symfony/Component/Filesystem new file mode 160000 index 000000000..f475e8299 --- /dev/null +++ b/vendor/Symfony/Component/Filesystem @@ -0,0 +1 @@ +Subproject commit f475e8299ff7bffbbd858bef85d3c80036f13877 diff --git a/vendor/Symfony/Component/Finder b/vendor/Symfony/Component/Finder new file mode 160000 index 000000000..b3adc8d5c --- /dev/null +++ b/vendor/Symfony/Component/Finder @@ -0,0 +1 @@ +Subproject commit b3adc8d5c29593db93c0abc4711a1e25fd3a6fa0 diff --git a/vendor/Symfony/Component/Locale b/vendor/Symfony/Component/Locale new file mode 160000 index 000000000..b7ea9a154 --- /dev/null +++ b/vendor/Symfony/Component/Locale @@ -0,0 +1 @@ +Subproject commit b7ea9a154faac6c27cacc74b60de325b481c4d8e diff --git a/vendor/Symfony/Component/Yaml b/vendor/Symfony/Component/Yaml new file mode 160000 index 000000000..2552c643a --- /dev/null +++ b/vendor/Symfony/Component/Yaml @@ -0,0 +1 @@ +Subproject commit 2552c643a158ee7fb6c52c0dd55806055c575841 diff --git a/vendor/Umpirsky/Country/Dumper/Dumper.php b/vendor/Umpirsky/Country/Dumper/Dumper.php new file mode 100644 index 000000000..01d2455c4 --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/Dumper.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper; + +use Umpirsky\Country\Dumper\DumperInterface; + +/** + * Abstract dumper. + * + * @author Саша Стаменковић + */ +abstract class Dumper implements DumperInterface { + + /** + * Gets dumper format. + * + * @return string + */ + public function getFormat() { + + $className = get_class($this); + return strtolower(substr($className, strrpos($className, '\\') + 1)); + } + +} diff --git a/vendor/Umpirsky/Country/Dumper/DumperInterface.php b/vendor/Umpirsky/Country/Dumper/DumperInterface.php new file mode 100644 index 000000000..50174b099 --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/DumperInterface.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper; + +/** + * Dumper interface. + * + * @author Саша Стаменковић + */ +interface DumperInterface { + + /** + * Dumps data into specific format. + * + * @param array $data + * @return string + */ + public function dump(array $data); +} diff --git a/vendor/Umpirsky/Country/Dumper/Format/Json.php b/vendor/Umpirsky/Country/Dumper/Format/Json.php new file mode 100644 index 000000000..c5bb3376f --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/Format/Json.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper\Format; + +use Umpirsky\Country\Dumper\Dumper; + +/** + * Json dumper. + * + * @author Саша Стаменковић + */ +class Json extends Dumper { + + /** + * {@inheritdoc} + */ + public function dump(array $data) { + + return json_encode($data); + } +} diff --git a/vendor/Umpirsky/Country/Dumper/Format/MySql.php b/vendor/Umpirsky/Country/Dumper/Format/MySql.php new file mode 100644 index 000000000..839957f11 --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/Format/MySql.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper\Format; + +use Umpirsky\Country\Dumper\Dumper; +use Symfony\Component\Yaml\Yaml as SymfonyYaml; + +/** + * MySQL dumper. + * + * @author Саша Стаменковић + */ +class MySql extends Dumper { + + /** + * {@inheritdoc} + */ + public function dump(array $data) { + + $sql = "CREATE TABLE `country` (" . PHP_EOL . + " `id` char(2) NOT NULL COMMENT 'ISO 3166-1 country code'," . PHP_EOL . + " `name` varchar(64) DEFAULT NULL COMMENT 'Country name'," . PHP_EOL . + " PRIMARY KEY (`id`)" . PHP_EOL . + ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores country names';" . PHP_EOL . PHP_EOL . + + "INSERT INTO `country`" . PHP_EOL . + "(`id`, `name`)" . PHP_EOL . + "VALUES" . PHP_EOL + ; + + foreach ($data as $id => $name) { + $sql .= sprintf("('%s', '%s')%s", $id, $name, PHP_EOL); + } + + $sql .= ';'; + + return $sql; + } +} diff --git a/vendor/Umpirsky/Country/Dumper/Format/Php.php b/vendor/Umpirsky/Country/Dumper/Format/Php.php new file mode 100644 index 000000000..b240336e3 --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/Format/Php.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper\Format; + +use Umpirsky\Country\Dumper\Dumper; + +/** + * PHP dumper. + * + * @author Саша Стаменковић + */ +class Php extends Dumper { + + /** + * {@inheritdoc} + */ + public function dump(array $data) { + + return sprintf(' + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper\Format; + +use Umpirsky\Country\Dumper\Dumper; +use Symfony\Component\Yaml\Yaml as SymfonyYaml; + +/** + * Yaml dumper. + * + * @author Саша Стаменковић + */ +class Yaml extends Dumper { + + /** + * {@inheritdoc} + */ + public function dump(array $data) { + + return SymfonyYaml::dump($data); + } +} diff --git a/vendor/Umpirsky/Country/Dumper/Iterator.php b/vendor/Umpirsky/Country/Dumper/Iterator.php new file mode 100644 index 000000000..a6be075cf --- /dev/null +++ b/vendor/Umpirsky/Country/Dumper/Iterator.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Umpirsky\Country\Dumper; + +use Symfony\Component\Finder\Finder; + +/** + * Iterates through various dumper formats. + * + * @author Саша Стаменковић + */ +class Iterator implements \Iterator { + + protected $values; + + public function __construct() { + + $finder = new Finder(); + $iterator = $finder + ->files() + ->name('*.php') + ->depth(0) + ->in(__DIR__ . '/Format'); + + $this->values = array(); + foreach ($iterator as $file) { + $dumperClassName = '\\Umpirsky\\Country\\Dumper\\Format\\' . strstr($file->getFilename(), '.', true); + $this->attach(new $dumperClassName()); + } + + $this->rewind(); + } + + public function attach($fileinfo) { + $this->values[] = $fileinfo; + } + + public function rewind() { + reset($this->values); + } + + public function valid() { + return false !== $this->current(); + } + + public function next() { + next($this->values); + } + + public function current() { + return current($this->values); + } + + public function key() { + return key($this->values); + } +}