Skip to content

Commit

Permalink
Use symfony/var-exporter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
giggsey committed Nov 4, 2024
1 parent 2a9c0a9 commit 1bc6e91
Show file tree
Hide file tree
Showing 429 changed files with 1,722 additions and 3,012 deletions.
38 changes: 14 additions & 24 deletions build/Build/DataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
use RuntimeException;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\VarExporter\VarExporter;

class DataBuilder
{
protected const GENERATION_HEADER = <<<EOT
/**
* Locale @generated from CLDR version {{ version }}
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/
EOT;

/**
Expand Down Expand Up @@ -101,7 +99,7 @@ public function generate(string $version, string $inputDir, string $outputDir, O
continue;
}

$this->writeTerritoryFile($outputDir, $version, $locale, $countryData);
$this->writeTerritoryFile($outputDir, $locale, $countryData);

$writtenCountries[strtolower($locale)] = '';

Expand All @@ -110,7 +108,7 @@ public function generate(string $version, string $inputDir, string $outputDir, O

ksort($writtenCountries);

$this->writeMappingFile($outputDir, $version, $writtenCountries);
$this->writeMappingFile($outputDir, $writtenCountries);

$this->writeVersionFile($outputDir, $version);

Expand Down Expand Up @@ -206,26 +204,23 @@ protected function loadTerritories(string $inputDir, array $localeList): array
return $countries;
}

/**
* @param string $version CLDR Version
*/
private function writeTerritoryFile(string $outputDir, string $version, string $locale, array $data): void
private function writeTerritoryFile(string $outputDir, string $locale, array $data): void
{
$phpSource = '<?php'
. PHP_EOL
. $this->generateFileHeader($version)
. 'return ' . var_export($data, true) . ';'
. static::GENERATION_HEADER
. 'return ' . VarExporter::export($data) . ';'
. PHP_EOL;

file_put_contents($outputDir . strtolower($locale) . '.php', $phpSource);
}

private function writeMappingFile(string $outputDir, string $version, array $countryList): void
private function writeMappingFile(string $outputDir, array $countryList): void
{
$phpSource = '<?php'
. PHP_EOL
. $this->generateFileHeader($version)
. 'return ' . var_export($countryList, true) . ';'
. static::GENERATION_HEADER
. 'return ' . VarExporter::export($countryList) . ';'
. PHP_EOL;

file_put_contents($outputDir . '_list.php', $phpSource);
Expand All @@ -235,15 +230,10 @@ private function writeVersionFile(string $outputDir, string $version): void
{
$phpSource = '<?php'
. PHP_EOL
. $this->generateFileHeader($version)
. 'return ' . var_export($version, true) . ';'
. static::GENERATION_HEADER
. 'return ' . VarExporter::export($version) . ';'
. PHP_EOL;

file_put_contents($outputDir . '_version.php', $phpSource);
}

private function generateFileHeader($version): string
{
return str_replace('{{ version }}', $version, static::GENERATION_HEADER);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"symfony/filesystem": "^5.0|^6.0",
"symfony/process": "^5.0|^6.0",
"symfony/finder": "^5.0|^6.0",
"symfony/var-exporter": "^5.2|^6.0",
"friendsofphp/php-cs-fixer": "^3.64"
},
"autoload": {
Expand Down
11 changes: 4 additions & 7 deletions data/_list.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'af' => '',
'agq' => '',
'ak' => '',
Expand Down
9 changes: 3 additions & 6 deletions data/_version.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return '45.0.0';
11 changes: 4 additions & 7 deletions data/af.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'Ascensioneiland',
'AD' => 'Andorra',
'AE' => 'Verenigde Arabiese Emirate',
Expand Down
11 changes: 4 additions & 7 deletions data/agq.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AD' => 'Àndolà',
'AE' => 'Yùnaetɛ Alab ɛmelɛ̀',
'AF' => 'Àfɨ̀ganìsɨ̀tân',
Expand Down
11 changes: 4 additions & 7 deletions data/ak.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AD' => 'Andora',
'AE' => 'United Arab Emirates',
'AF' => 'Afganistan',
Expand Down
11 changes: 4 additions & 7 deletions data/am.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'አሴንሽን ደሴት',
'AD' => 'አንዶራ',
'AE' => 'የተባበሩት ዓረብ ኤምሬትስ',
Expand Down
11 changes: 4 additions & 7 deletions data/ar-ly.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'EA' => 'سبتة ومليلية',
'MS' => 'مونتيسيرات',
'UY' => 'أوروغواي',
Expand Down
11 changes: 4 additions & 7 deletions data/ar-sa.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'جزيرة أسينشين',
'EA' => 'سبتة ومليلية',
'MO' => 'ماكاو الصينية (منطقة إدارية خاصة)',
Expand Down
11 changes: 4 additions & 7 deletions data/ar.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'جزيرة أسينشيون',
'AD' => 'أندورا',
'AE' => 'الإمارات العربية المتحدة',
Expand Down
11 changes: 4 additions & 7 deletions data/as.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'এচেনচিয়ন দ্বীপ',
'AD' => 'আন্দোৰা',
'AE' => 'সংযুক্ত আৰব আমিৰাত',
Expand Down
11 changes: 4 additions & 7 deletions data/asa.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AD' => 'Andora',
'AE' => 'Falme dha Kiarabu',
'AF' => 'Afuganistani',
Expand Down
11 changes: 4 additions & 7 deletions data/ast.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'Islla Ascensión',
'AD' => 'Andorra',
'AE' => 'Emiratos Árabes Xuníos',
Expand Down
11 changes: 4 additions & 7 deletions data/az-cyrl.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'Аскенсон адасы',
'AD' => 'Андорра',
'AE' => 'Бирләшмиш Әрәб Әмирликләри',
Expand Down
11 changes: 4 additions & 7 deletions data/az.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AC' => 'Askenson adası',
'AD' => 'Andorra',
'AE' => 'Birləşmiş Ərəb Əmirlikləri',
Expand Down
11 changes: 4 additions & 7 deletions data/bas.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
/**
* Locale @generated from CLDR version 45.0.0
* See README.md for more information.
*
* @internal
*
* Locale data file
* This file has been @generated from Locale data
* Do not modify or use this file directly!
* @internal
*/

return [
return [
'AD' => 'Àŋdɔ̂r',
'AE' => 'Àdnà i Bilɔ̀ŋ bi Arābìà',
'AF' => 'Àfgànìstâŋ',
Expand Down
Loading

0 comments on commit 1bc6e91

Please sign in to comment.