PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/rokcommon/Doctrine/Validator/Country.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 305 lines | 260 code | 4 blank | 41 comment | 1 complexity | 97d47dc352d72fc783a62c8a1489a498 MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: Country.php 48519 2012-02-03 23:18:52Z btowles $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. /**
  22. * Doctrine_Validator_Country
  23. *
  24. * @package Doctrine
  25. * @subpackage Validator
  26. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  27. * @link www.doctrine-project.org
  28. * @since 1.0
  29. * @version $Revision: 7490 $
  30. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
  31. */
  32. class Doctrine_Validator_Country extends Doctrine_Validator_Driver
  33. {
  34. private static $countries = array(
  35. 'ad' => 'Andorra',
  36. 'ae' => 'United Arab Emirates',
  37. 'af' => 'Afghanistan',
  38. 'ag' => 'Antigua and Barbuda',
  39. 'ai' => 'Anguilla',
  40. 'al' => 'Albania',
  41. 'am' => 'Armenia',
  42. 'an' => 'Netherlands Antilles',
  43. 'ao' => 'Angola',
  44. 'aq' => 'Antarctica',
  45. 'ar' => 'Argentina',
  46. 'as' => 'American Samoa',
  47. 'at' => 'Austria',
  48. 'au' => 'Australia',
  49. 'aw' => 'Aruba',
  50. 'az' => 'Azerbaijan',
  51. 'ba' => 'Bosnia Hercegovina',
  52. 'bb' => 'Barbados',
  53. 'bd' => 'Bangladesh',
  54. 'be' => 'Belgium',
  55. 'bf' => 'Burkina Faso',
  56. 'bg' => 'Bulgaria',
  57. 'bh' => 'Bahrain',
  58. 'bi' => 'Burundi',
  59. 'bj' => 'Benin',
  60. 'bm' => 'Bermuda',
  61. 'bn' => 'Brunei Darussalam',
  62. 'bo' => 'Bolivia',
  63. 'br' => 'Brazil',
  64. 'bs' => 'Bahamas',
  65. 'bt' => 'Bhutan',
  66. 'bv' => 'Bouvet Island',
  67. 'bw' => 'Botswana',
  68. 'by' => 'Belarus (Byelorussia)',
  69. 'bz' => 'Belize',
  70. 'ca' => 'Canada',
  71. 'cc' => 'Cocos Islands',
  72. 'cd' => 'Congo, The Democratic Republic of the',
  73. 'cf' => 'Central African Republic',
  74. 'cg' => 'Congo',
  75. 'ch' => 'Switzerland',
  76. 'ci' => 'Ivory Coast',
  77. 'ck' => 'Cook Islands',
  78. 'cl' => 'Chile',
  79. 'cm' => 'Cameroon',
  80. 'cn' => 'China',
  81. 'co' => 'Colombia',
  82. 'cr' => 'Costa Rica',
  83. 'cs' => 'Czechoslovakia',
  84. 'cu' => 'Cuba',
  85. 'cv' => 'Cape Verde',
  86. 'cx' => 'Christmas Island',
  87. 'cy' => 'Cyprus',
  88. 'cz' => 'Czech Republic',
  89. 'de' => 'Germany',
  90. 'dj' => 'Djibouti',
  91. 'dk' => 'Denmark',
  92. 'dm' => 'Dominica',
  93. 'do' => 'Dominican Republic',
  94. 'dz' => 'Algeria',
  95. 'ec' => 'Ecuador',
  96. 'ee' => 'Estonia',
  97. 'eg' => 'Egypt',
  98. 'eh' => 'Western Sahara',
  99. 'er' => 'Eritrea',
  100. 'es' => 'Spain',
  101. 'et' => 'Ethiopia',
  102. 'fi' => 'Finland',
  103. 'fj' => 'Fiji',
  104. 'fk' => 'Falkland Islands',
  105. 'fm' => 'Micronesia',
  106. 'fo' => 'Faroe Islands',
  107. 'fr' => 'France',
  108. 'fx' => 'France, Metropolitan FX',
  109. 'ga' => 'Gabon',
  110. 'gb' => 'United Kingdom (Great Britain)',
  111. 'gd' => 'Grenada',
  112. 'ge' => 'Georgia',
  113. 'gf' => 'French Guiana',
  114. 'gh' => 'Ghana',
  115. 'gi' => 'Gibraltar',
  116. 'gl' => 'Greenland',
  117. 'gm' => 'Gambia',
  118. 'gn' => 'Guinea',
  119. 'gp' => 'Guadeloupe',
  120. 'gq' => 'Equatorial Guinea',
  121. 'gr' => 'Greece',
  122. 'gs' => 'South Georgia and the South Sandwich Islands',
  123. 'gt' => 'Guatemala',
  124. 'gu' => 'Guam',
  125. 'gw' => 'Guinea-bissau',
  126. 'gy' => 'Guyana',
  127. 'hk' => 'Hong Kong',
  128. 'hm' => 'Heard and McDonald Islands',
  129. 'hn' => 'Honduras',
  130. 'hr' => 'Croatia',
  131. 'ht' => 'Haiti',
  132. 'hu' => 'Hungary',
  133. 'id' => 'Indonesia',
  134. 'ie' => 'Ireland',
  135. 'il' => 'Israel',
  136. 'in' => 'India',
  137. 'io' => 'British Indian Ocean Territory',
  138. 'iq' => 'Iraq',
  139. 'ir' => 'Iran',
  140. 'is' => 'Iceland',
  141. 'it' => 'Italy',
  142. 'jm' => 'Jamaica',
  143. 'jo' => 'Jordan',
  144. 'jp' => 'Japan',
  145. 'ke' => 'Kenya',
  146. 'kg' => 'Kyrgyzstan',
  147. 'kh' => 'Cambodia',
  148. 'ki' => 'Kiribati',
  149. 'km' => 'Comoros',
  150. 'kn' => 'Saint Kitts and Nevis',
  151. 'kp' => 'North Korea',
  152. 'kr' => 'South Korea',
  153. 'kw' => 'Kuwait',
  154. 'ky' => 'Cayman Islands',
  155. 'kz' => 'Kazakhstan',
  156. 'la' => 'Laos',
  157. 'lb' => 'Lebanon',
  158. 'lc' => 'Saint Lucia',
  159. 'li' => 'Lichtenstein',
  160. 'lk' => 'Sri Lanka',
  161. 'lr' => 'Liberia',
  162. 'ls' => 'Lesotho',
  163. 'lt' => 'Lithuania',
  164. 'lu' => 'Luxembourg',
  165. 'lv' => 'Latvia',
  166. 'ly' => 'Libya',
  167. 'ma' => 'Morocco',
  168. 'mc' => 'Monaco',
  169. 'md' => 'Moldova Republic',
  170. 'mg' => 'Madagascar',
  171. 'mh' => 'Marshall Islands',
  172. 'mk' => 'Macedonia, The Former Yugoslav Republic of',
  173. 'ml' => 'Mali',
  174. 'mm' => 'Myanmar',
  175. 'mn' => 'Mongolia',
  176. 'mo' => 'Macau',
  177. 'mp' => 'Northern Mariana Islands',
  178. 'mq' => 'Martinique',
  179. 'mr' => 'Mauritania',
  180. 'ms' => 'Montserrat',
  181. 'mt' => 'Malta',
  182. 'mu' => 'Mauritius',
  183. 'mv' => 'Maldives',
  184. 'mw' => 'Malawi',
  185. 'mx' => 'Mexico',
  186. 'my' => 'Malaysia',
  187. 'mz' => 'Mozambique',
  188. 'na' => 'Namibia',
  189. 'nc' => 'New Caledonia',
  190. 'ne' => 'Niger',
  191. 'nf' => 'Norfolk Island',
  192. 'ng' => 'Nigeria',
  193. 'ni' => 'Nicaragua',
  194. 'nl' => 'Netherlands',
  195. 'no' => 'Norway',
  196. 'np' => 'Nepal',
  197. 'nr' => 'Nauru',
  198. 'nt' => 'Neutral Zone',
  199. 'nu' => 'Niue',
  200. 'nz' => 'New Zealand',
  201. 'om' => 'Oman',
  202. 'pa' => 'Panama',
  203. 'pe' => 'Peru',
  204. 'pf' => 'French Polynesia',
  205. 'pg' => 'Papua New Guinea',
  206. 'ph' => 'Philippines',
  207. 'pk' => 'Pakistan',
  208. 'pl' => 'Poland',
  209. 'pm' => 'St. Pierre and Miquelon',
  210. 'pn' => 'Pitcairn',
  211. 'pr' => 'Puerto Rico',
  212. 'pt' => 'Portugal',
  213. 'pw' => 'Palau',
  214. 'py' => 'Paraguay',
  215. 'qa' => 'Qatar',
  216. 're' => 'Reunion',
  217. 'ro' => 'Romania',
  218. 'ru' => 'Russia',
  219. 'rw' => 'Rwanda',
  220. 'sa' => 'Saudi Arabia',
  221. 'sb' => 'Solomon Islands',
  222. 'sc' => 'Seychelles',
  223. 'sd' => 'Sudan',
  224. 'se' => 'Sweden',
  225. 'sg' => 'Singapore',
  226. 'sh' => 'St. Helena',
  227. 'si' => 'Slovenia',
  228. 'sj' => 'Svalbard and Jan Mayen Islands',
  229. 'sk' => 'Slovakia (Slovak Republic)',
  230. 'sl' => 'Sierra Leone',
  231. 'sm' => 'San Marino',
  232. 'sn' => 'Senegal',
  233. 'so' => 'Somalia',
  234. 'sr' => 'Suriname',
  235. 'st' => 'Sao Tome and Principe',
  236. 'sv' => 'El Salvador',
  237. 'sy' => 'Syria',
  238. 'sz' => 'Swaziland',
  239. 'tc' => 'Turks and Caicos Islands',
  240. 'td' => 'Chad',
  241. 'tf' => 'French Southern Territories',
  242. 'tg' => 'Togo',
  243. 'th' => 'Thailand',
  244. 'tj' => 'Tajikistan',
  245. 'tk' => 'Tokelau',
  246. 'tm' => 'Turkmenistan',
  247. 'tn' => 'Tunisia',
  248. 'to' => 'Tonga',
  249. 'tp' => 'East Timor',
  250. 'tr' => 'Turkey',
  251. 'tt' => 'Trinidad, Tobago',
  252. 'tv' => 'Tuvalu',
  253. 'tw' => 'Taiwan',
  254. 'tz' => 'Tanzania',
  255. 'ua' => 'Ukraine',
  256. 'ug' => 'Uganda',
  257. 'uk' => 'United Kingdom',
  258. 'um' => 'United States Minor Islands',
  259. 'us' => 'United States of America',
  260. 'uy' => 'Uruguay',
  261. 'uz' => 'Uzbekistan',
  262. 'va' => 'Vatican City',
  263. 'vc' => 'Saint Vincent, Grenadines',
  264. 've' => 'Venezuela',
  265. 'vg' => 'Virgin Islands (British)',
  266. 'vi' => 'Virgin Islands (USA)',
  267. 'vn' => 'Viet Nam',
  268. 'vu' => 'Vanuatu',
  269. 'wf' => 'Wallis and Futuna Islands',
  270. 'ws' => 'Samoa',
  271. 'ye' => 'Yemen',
  272. 'yt' => 'Mayotte',
  273. 'yu' => 'Yugoslavia',
  274. 'za' => 'South Africa',
  275. 'zm' => 'Zambia',
  276. 'zr' => 'Zaire',
  277. 'zw' => 'Zimbabwe');
  278. /**
  279. * returns all available country codes
  280. *
  281. * @return array
  282. */
  283. public static function getCountries()
  284. {
  285. return self::$countries;
  286. }
  287. /**
  288. * checks if given value is a valid country code
  289. *
  290. * @param mixed $value
  291. * @return boolean
  292. */
  293. public function validate($value)
  294. {
  295. if (is_null($value)) {
  296. return true;
  297. }
  298. $value = strtolower($value);
  299. return isset(self::$countries[$value]);
  300. }
  301. }