/** * Copies the data from the country to the destination * * @param CountryInterface $source Source * @param Country $destination Destination */ public function copyCountry(CountryInterface $source, Country $destination) { $code = $source->getCode(); $name = $source->getName(); $domain = $source->getDomain(); $postalCodeFormat = $source->getPostalCodeFormat(); $postalCodeRegex = $source->getPostalCodeRegex(); $phonePrefix = $source->getPhonePrefix(); // Copy the country code if ($code !== $destination->getCode()) { $destination->setCode($code); } // Copy the country name if ($name !== $destination->getName()) { $destination->setName($name); } // Copy the top level domain suffix if ($domain !== $destination->getDomain()) { $destination->setDomain($domain); } // Copy the postal code format if ($postalCodeFormat !== $destination->getPostalCodeFormat()) { $destination->setPostalCodeFormat($postalCodeFormat); } // Copy the postal code regex if ($postalCodeRegex !== $destination->getPostalCodeRegex()) { $destination->setPostalCodeRegex($postalCodeRegex); } // Copy the phone prefix if ($phonePrefix !== $destination->getPhonePrefix()) { $destination->setPhonePrefix($phonePrefix); } }
/** * Imports an individual locality into the the locality repositories * * @param LocalityRepositoryInterface $localityRepository Locality repository * @param Locality $locality Locality * @param CountryInterface $country Country * @param Filter $filter Locality Filter * @param LoggerInterface $log Import log */ public function importLocality(LocalityRepositoryInterface $localityRepository, Locality $locality, CountryInterface $country = null, Filter $filter, LoggerInterface $log = null) { $log = $log ?: new NullLogger(); if ($filter != null && $filter->applyRules($locality) == false) { return null; } $countryRepository = $this->getCountryRepository(); $timezoneRepository = $this->getTimezoneRepository(); // Load the country for the locality if required if (!$country || $locality->getCountryCode() !== $country->getCode()) { $country = $countryRepository->getCountry($locality->getCountryCode()); if (!$country) { $log->error("Country code '{code}' does not exist in repository {repository}", ['code' => $country, 'repository' => get_class($countryRepository)]); return null; } } // Set the country $locality->setCountry($country); // Load the timezone for the locality if ($locality->getTimezoneIdentifier()) { $timezone = $timezoneRepository->getTimezone($locality->getTimezoneIdentifier()); if (!$timezone) { $log->warning("Timezone code '{code}' does not exist in repository {repository}", ['code' => $locality->getTimezoneIdentifier(), 'repository' => get_class($timezoneRepository)]); } } else { $timezone = null; } // Set the timezone $locality->setTimezone($timezone); // Register that the locality was imported /*$log->debug("'{locality}' imported into repository {repository}", [ 'locality' => $locality->getNameAscii(), 'repository' => get_class($localityRepository), ]);*/ // Import the localty into the repository $locality = $localityRepository->importLocality($locality); return $locality; }
/** * Returns the default file for the specified country * * @param CountryInterface $country Country * * @return string */ public function getDefaultCountryFile(CountryInterface $country) { return sprintf('zip://%1$s/%2$s.zip#%2$s.txt', self::GEONAMES_EXPORT_PATH, $country->getCode()); }