Пример #1
0
    }
    $addressFormats[$countryCode] = $addressFormat;
}
echo "Writing the final definitions to disk.\n";
// Subdivisions are stored in JSON.
foreach ($groupedSubdivisions as $parentId => $subdivisions) {
    file_put_json('subdivision/' . $parentId . '.json', $subdivisions);
}
// Generate the subdivision depths for each country.
$depths = generate_subdivision_depths($foundCountries);
foreach ($depths as $countryCode => $depth) {
    $addressFormats[$countryCode]['subdivision_depth'] = $depth;
}
// Address formats are stored in PHP, then manually transferred to
// AddressFormatRepository.
file_put_php('address_formats.php', $addressFormats);
echo "Done.\n";
/**
 * Converts the provided data into json and writes it to the disk.
 */
function file_put_json($filename, $data)
{
    $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    // Indenting with tabs instead of 4 spaces gives us 20% smaller files.
    $data = str_replace('    ', "\t", $data);
    file_put_contents($filename, $data);
}
/**
 * Converts the provided data into php and writes it to the disk.
 */
function file_put_php($filename, $data)
Пример #2
0
function file_set_array($filename = '', &$array = array(), $array_name = 'array')
{
    file_put_php($filename, '$' . $array_name . ' = ' . var_export($array, true) . ';');
}