GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — CLDR/lib/Territory.php at master · DatingVIP/CLDR Expand file tree/ Copy pathTerritory.phpMore file actions 270 lines (230 loc) · 6.08 KB / Copy pathTerritory.phpFile metadata and controls270 lines (230 loc) · 6.08 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 <?php /* * This file is part of the ICanBoogie package. * * (c) Olivier Laviale <[email protected]> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace ICanBoogie\CLDR; use DateTimeImmutable; use DateTimeInterface; use ICanBoogie\Accessor\AccessorTrait; use Throwable; use function current; use function extract; use function in_array; use function key; use function strlen; use function strpos; use function substr; /** * A territory. * * @property-read array<string, mixed> $containment The `territoryContainment` data. * @property-read array<string, mixed> $info The `territoryInfo` data. * @property-read array<string, mixed> $currencies The currencies available in the country. * @property-read Currency|null $currency The current currency. * @property-read string $first_day The code of the first day of the week for the territory. * @property-read string $weekend_start The code of the first day of the weekend. * @property-read string $weekend_end The code of the last day of the weekend. * @property-read string|bool $language The ISO code of the official language, or `false` if it * cannot be determined. * @property-read string $name_as_* The name of the territory in the specified language. * @property-read int $population The population of the territory. * * @see http://www.unicode.org/reports/tr35/tr35-numbers.html#Supplemental_Currency_Data */ #[\AllowDynamicProperties] final class Territory { /** * @uses lazy_get_containment * @uses lazy_get_currencies * @uses lazy_get_currency * @uses lazy_get_info * @uses lazy_get_language * @uses get_first_day * @uses get_weekend_start * @uses get_weekend_end * @uses get_population */ use AccessorTrait; use RepositoryPropertyTrait; use CodePropertyTrait; /** * @return array<string, mixed> */ private function lazy_get_containment(): array { return $this->retrieve_from_supplemental('territoryContainment'); } /** * @return array<string, mixed> */ private function lazy_get_currencies(): array { return $this->repository->supplemental['currencyData']['region'][$this->code]; } /** * @throws Throwable */ private function lazy_get_currency(): ?Currency { return $this->currency_at(); } /** * @return array<string, mixed> */ private function lazy_get_info(): array { return $this->retrieve_from_supplemental('territoryInfo'); } /** * Return the ISO code of the official language of the territory. * * @return string|bool The ISO code of the official language, or `false` if it cannot be * determined. */ private function lazy_get_language() { $info = $this->info; foreach ($info['languagePopulation'] as $language => $lp) { if (empty($lp['_officialStatus']) || ($lp['_officialStatus'] != "official" && $lp['_officialStatus'] != "de_facto_official")) { continue; } return $language; } return false; } private function get_first_day(): string { return $this->resolve_week_data('firstDay'); } private function get_weekend_start(): string { return $this->resolve_week_data('weekendStart'); } private function get_weekend_end(): string { return $this->resolve_week_data('weekendEnd'); } private function get_population(): int { $info = $this->info; return (int) $info['_population']; } public function __construct(Repository $repository, string $code) { $this->repository = $repository; $this->code = $code; $repository->territories->assert_defined($code); } /** * @return mixed */ public function __get(string $property) { if (strpos($property, 'name_as_') === 0) { $locale_code = substr($property, strlen('name_as_')); $locale_code = strtr($locale_code, '_', '-'); return $this->name_as($locale_code); } return $this->accessor_get($property); } /** * @return array<string, mixed> */ private function retrieve_from_supplemental(string $section): array { return $this->repository->supplemental[$section][$this->code]; } /** * Return the currency used in the territory at a point in time. * * @param DateTimeInterface|mixed $date * * @throws Throwable */ public function currency_at($date = null): ?Currency { $date = $this->ensure_is_datetime($date); $code = $this->find_currency_at($this->currencies, $date->format('Y-m-d')); if (!$code) { return null; } return new Currency($this->repository, $code); } /** * Return the currency in a list used at a point in time. * * @param array<string, mixed> $currencies */ private function find_currency_at(array $currencies, string $normalized_date): string { $rc = false; foreach ($currencies as $currency) { $name = key($currency); $interval = current($currency); $_from = null; $_to = null; extract($interval); // @phpstan-ignore-next-line if (($_from && $_from > $normalized_date) || ($_to && $_to < $normalized_date)) { continue; } $rc = $name; } return $rc; } /** * Whether the territory contains the specified territory. */ public function is_containing(string $code): bool { $containment = $this->containment; return in_array($code, $containment['_contains']); } /** * Return the name of the territory localized according to the specified locale code. */ public function name_as(string $locale_code): string { return $this->localize($locale_code)->name; } /** * Localize the currency. */ public function localize(string $locale_code): LocalizedTerritory { return $this->repository->locales[$locale_code]->localize($this); } private function resolve_week_data(string $which): string { $code = $this->code; $data = $this->repository->supplemental['weekData'][$which]; return empty($data[$code]) ? $data['001'] : $data[$code]; } /** * @param DateTimeInterface|string|null $datetime * * @throws Throwable */ private function ensure_is_datetime($datetime): DateTimeInterface { if ($datetime === null) { return new DateTimeImmutable(); } return $datetime instanceof DateTimeInterface ? $datetime : new DateTimeImmutable($datetime); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |