Skip to content

Commit

Permalink
Smaller metadata files
Browse files Browse the repository at this point in the history
 - Use symfony/var-exporter to generate better PHP
 - Skip some booleans that match their default value
 - Rename some properties to reduce string size
  • Loading branch information
giggsey committed Apr 29, 2024
1 parent 7e31d93 commit 040824f
Show file tree
Hide file tree
Showing 539 changed files with 40,971 additions and 56,478 deletions.
18 changes: 5 additions & 13 deletions build/BuildMetadataPHPFromXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace libphonenumber\buildtools;

use libphonenumber\PhoneMetadata;
use Symfony\Component\VarExporter\VarExporter;

/**
* Tool to convert phone number metadata from the XML format to protocol buffer format.
Expand Down Expand Up @@ -61,7 +62,7 @@ private function writeMetadataToFile(array $metadataCollection, string $filePref

$data = '<?php' . PHP_EOL
. self::GENERATION_COMMENT . PHP_EOL
. 'return ' . \var_export($metadata->toArray(), true) . ';' . PHP_EOL;
. 'return ' . VarExporter::export($metadata->toArray()) . ';' . PHP_EOL;

\file_put_contents($filePrefix . '_' . $regionCode . '.php', $data);
}
Expand Down Expand Up @@ -94,22 +95,13 @@ private function writeCountryCallingCodeMappingToFile(array $countryCodeToRegion

if ($hasRegionCodes && $hasCountryCodes) {
$data .= self::MAP_COMMENT . PHP_EOL;
$data .= " public const {$constName} = " . \var_export(
$countryCodeToRegionCodeMap,
true
) . ';' . PHP_EOL;
$data .= " public const {$constName} = " . VarExporter::export($countryCodeToRegionCodeMap) . ';' . PHP_EOL;
} elseif ($hasCountryCodes) {
$data .= self::COUNTRY_CODE_SET_COMMENT . PHP_EOL;
$data .= " public const {$constName} = " . \var_export(
\array_keys($countryCodeToRegionCodeMap),
true
) . ';' . PHP_EOL;
$data .= " public const {$constName} = " . VarExporter::export(\array_keys($countryCodeToRegionCodeMap)) . ';' . PHP_EOL;
} else {
$data .= self::REGION_CODE_SET_COMMENT . PHP_EOL;
$data .= " public const {$constName} = " . \var_export(
$countryCodeToRegionCodeMap[0],
true
) . ';' . PHP_EOL;
$data .= " public const {$constName} = " . VarExporter::export($countryCodeToRegionCodeMap[0]) . ';' . PHP_EOL;
}

$data .= PHP_EOL .
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.2",
"phpunit/phpunit": "^10.5",
"symfony/console": "^6.0"
"symfony/console": "^6.0",
"symfony/var-exporter": "^6.0"
},
"conflict": {
"giggsey/libphonenumber-for-php": "*"
Expand Down
Loading

0 comments on commit 040824f

Please sign in to comment.