Exception
8 months ago
Guards.php
8 months ago
ISO3166.php
8 months ago
ISO3166DataProvider.php
8 months ago
ISO3166DataValidator.php
8 months ago
ISO3166WithAliases.php
8 months ago
ISO3166WithAliases.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /* |
| 6 | * (c) Rob Bast <rob.bast@gmail.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view |
| 9 | * the LICENSE file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Automattic\WooCommerce\Vendor\League\ISO3166; |
| 13 | |
| 14 | class ISO3166WithAliases implements ISO3166DataProvider |
| 15 | { |
| 16 | private ISO3166DataProvider $source; |
| 17 | |
| 18 | /** @type array<string, string> */ |
| 19 | public const aliases = [ |
| 20 | 'Bolivia' => 'Bolivia (Plurinational State of)', |
| 21 | 'Bolivia, Plurinational State of' => 'Bolivia (Plurinational State of)', |
| 22 | 'Congo-Kinshasa' => 'Congo (Democratic Republic of the)', |
| 23 | 'Congo, Democratic Republic of the' => 'Congo (Democratic Republic of the)', |
| 24 | 'Czech Republic' => 'Czechia', |
| 25 | 'Iran' => 'Iran (Islamic Republic of)', |
| 26 | 'North Korea' => 'Korea (Democratic People\'s Republic of)', |
| 27 | 'South Korea' => 'Korea (Republic of)', |
| 28 | 'Laos' => 'Lao People\'s Democratic Republic', |
| 29 | 'Micronesia' => 'Micronesia (Federated States of)', |
| 30 | 'Moldova' => 'Moldova (Republic of)', |
| 31 | 'Palestine' => 'Palestine, State of', |
| 32 | 'Russia' => 'Russian Federation', |
| 33 | 'Saint Martin' => 'Saint Martin (French part)', |
| 34 | 'Sint Maarten' => 'Sint Maarten (Dutch part)', |
| 35 | 'Taiwan' => 'Taiwan (Province of China)', |
| 36 | 'Tanzania' => 'Tanzania, United Republic of', |
| 37 | 'United Kingdom' => 'United Kingdom of Great Britain and Northern Ireland', |
| 38 | 'United States' => 'United States of America', |
| 39 | 'USA' => 'United States of America', |
| 40 | 'Venezuela' => 'Venezuela (Bolivarian Republic of)', |
| 41 | 'Vietnam' => 'Viet Nam', |
| 42 | ]; |
| 43 | |
| 44 | public function __construct(ISO3166DataProvider $iso3166) |
| 45 | { |
| 46 | $this->source = $iso3166; |
| 47 | } |
| 48 | |
| 49 | public function name(string $name): array |
| 50 | { |
| 51 | foreach (self::aliases as $alias => $original) { |
| 52 | if (0 === strcasecmp($alias, $name)) { |
| 53 | $name = $original; |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return $this->source->name($name); |
| 59 | } |
| 60 | |
| 61 | public function alpha2(string $alpha2): array |
| 62 | { |
| 63 | return $this->source->alpha2($alpha2); |
| 64 | } |
| 65 | |
| 66 | public function alpha3(string $alpha3): array |
| 67 | { |
| 68 | return $this->source->alpha3($alpha3); |
| 69 | } |
| 70 | |
| 71 | public function numeric(string $numeric): array |
| 72 | { |
| 73 | return $this->source->numeric($numeric); |
| 74 | } |
| 75 | } |
| 76 |