currentFilePrefix = $currentFilePrefix; $this->metadataLoader = $metadataLoader; } /** * @inheritdoc */ public function getMetadataForRegion($regionCode) { if (!array_key_exists($regionCode, $this->regionToMetadataMap)) { // 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, $this->metadataLoader); } return $this->regionToMetadataMap[$regionCode]; } /** * @inheritdoc */ public function getMetadataForNonGeographicalRegion($countryCallingCode) { if (!array_key_exists($countryCallingCode, $this->countryCodeToNonGeographicalMetadataMap)) { $this->loadMetadataFromFile($this->currentFilePrefix, PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY, $countryCallingCode, $this->metadataLoader); } return $this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode]; } /** * @param string $filePrefix * @param string $regionCode * @param int $countryCallingCode * @param MetadataLoaderInterface $metadataLoader * @throws \RuntimeException */ public function loadMetadataFromFile($filePrefix, $regionCode, $countryCallingCode, MetadataLoaderInterface $metadataLoader) { $isNonGeoRegion = PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY === $regionCode; $fileName = $filePrefix . '_' . ($isNonGeoRegion ? $countryCallingCode : $regionCode) . '.php'; if (!is_readable($fileName)) { throw new \RuntimeException('missing metadata: ' . $fileName); } else { $data = $metadataLoader->loadMetadata($fileName); $metadata = new PhoneMetadata(); $metadata->fromArray($data); if ($isNonGeoRegion) { $this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode] = $metadata; } else { $this->regionToMetadataMap[$regionCode] = $metadata; } } } }