regionToMetadataMap[$regionCode])) { // The regionCode here will be valid and won't be '001', so we don't need to worry about // what to pass in for the country calling code. $this->loadMetadataFromFile($this->currentFilePrefix, $regionCode, 0); } return $this->regionToMetadataMap[$regionCode]; } public function getMetadataForNonGeographicalRegion(int $countryCallingCode): PhoneMetadata { if (!isset($this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode])) { $this->loadMetadataFromFile($this->currentFilePrefix, PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY, $countryCallingCode); } return $this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode]; } /** * @throws RuntimeException */ public function loadMetadataFromFile(string $filePrefix, string $regionCode, int $countryCallingCode): void { $regionCode = strtoupper($regionCode); $isNonGeoRegion = PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY === $regionCode; $class = $filePrefix . ($isNonGeoRegion ? $countryCallingCode : ucfirst($regionCode)); if (!class_exists($class)) { throw new RuntimeException('missing metadata: ' . $class); } $metadata = new $class(); if (!$metadata instanceof PhoneMetadata) { throw new RuntimeException('invalid metadata: ' . $class); } if ($isNonGeoRegion) { $this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode] = $metadata; } else { $this->regionToMetadataMap[$regionCode] = $metadata; } } }