Пример #1
0
 /**
  * @param ProgressAdapter|null $progressAdapter
  */
 public function updateAddressFormats(ProgressAdapter $progressAdapter = null)
 {
     $localeDataUri = $this->options->getLocaleDataUri();
     $dataPath = $this->options->getDataPath();
     $locales = json_decode($this->httpClient->setUri($localeDataUri)->send()->getContent());
     foreach (scandir($dataPath) as $file) {
         if (fnmatch('*.json', $file)) {
             unlink($dataPath . '/' . $file);
         }
     }
     $countryCodes = isset($locales->countries) ? explode('~', $locales->countries) : [];
     $countryCodes[] = 'ZZ';
     if ($progressAdapter !== null) {
         $progressBar = new ProgressBar($progressAdapter, 0, count($countryCodes));
     }
     foreach ($countryCodes as $countryCode) {
         file_put_contents($dataPath . '/' . $countryCode . '.json', $this->httpClient->setUri($localeDataUri . '/' . $countryCode)->send()->getContent());
         if (isset($progressBar)) {
             $progressBar->next();
         }
     }
     if (isset($progressBar)) {
         $progressBar->finish();
     }
     // We clearly don't want the "ZZ" in the array!
     array_pop($countryCodes);
     $writer = new PhpArrayWriter();
     $writer->setUseBracketArraySyntax(true);
     $writer->toFile($this->options->getCountryCodesPath(), $countryCodes, false);
 }
Пример #2
0
 /**
  * @return string[]
  */
 public function getCountryCodes()
 {
     if ($this->countryCodes !== null) {
         return $this->countryCodes;
     }
     return $this->countryCodes = (require $this->options->getCountryCodesPath());
 }
Пример #3
0
 /**
  * @covers ::setCountryCodesPath
  * @covers ::getCountryCodesPath
  */
 public function testGetSetCountryCodesPath()
 {
     $options = new Options();
     $options->setCountryCodesPath('foo');
     $this->assertSame('foo', $options->getCountryCodesPath());
 }