#!/usr/bin/env php ','',$tldEnumExport); $tldEnumExport = preg_replace('/[0-9]+/', '', $tldEnumExport); //$tldEnumExport = json_encode($tldEnum,\JSON_PRETTY_PRINT); if (false === file_put_contents($newTldEnumFile, $tldEnumExport,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldEnum.php' file",1); } if (false === file_put_contents($newTldEnumFile,static::TLD_ENUM_SOURCE_END_TLD_ENUM_CONST,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldEnum.php' file",1); } if (false === file_put_contents($newTldEnumFile,static::TLD_ENUM_SOURCE_END_CLASS,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldEnum.php' file",1); } echo "done\n"; if ($existingMd5!==null) { $newTldEnumMd5 = md5_file($newTldEnumFile); if ($existingMd5 == $newTldEnumMd5) { static::_echo_error("(NOTICE) ignoring newly generated 'TldEnum.php' file that is identical to the existing file (md5: $existingMd5, path: $tldEnumFile)"); return; } if (!unlink($tldEnumFile)) { static::_echo_error("(FATAL) failed to remove stale 'TldEnum.php': $tldEnumFile",1); } } if (!copy($newTldEnumFile,$tldEnumFile)) { static::_echo_error("(FATAL) failed to save new 'TldEnum.php': $tldEnumFile",1); } echo "saved new 'TldEnum.php' file\n"; } private static function _echo_error(string $str, int $fatal_exit_status=null) : void { if (substr($str,0,1)!=="\n") { $str .= "\n"; } $str = static::ME_NAME . ": ".$str; if (\PHP_SAPI=='cli') { fwrite(\STDERR,$str); } else { echo $str ; } if (is_int($fatal_exit_status)) { exit($fatal_exit_status); } } const TLD_ENUM_SOURCE_START_CLASS = <<