#!/usr/bin/env php $domain, 'description'=>$desc, 'type'=>$type, ]; $tldInfoElem = var_export($tldInfoElem, true); $tldInfoElem = str_replace('array','',$tldInfoElem); $tldInfoElem = str_replace('(','[',$tldInfoElem); $tldInfoElem = str_replace(')',']',$tldInfoElem); if ($i!=0) { $tldInfoElem = ",\n$tldInfoElem"; } if (false === file_put_contents($newTldInfoFile, $tldInfoElem,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldInfo.php' file",1); } $i++; } fclose($handle); echo "done\n"; } //echo "new TldInfo.php: $newTldInfoFile\n"; if (false === file_put_contents($newTldInfoFile,static::TLD_INFO_SOURCE_END_TLD_INFO_CONST,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldInfo.php' file",1); } if (false === file_put_contents($newTldInfoFile,static::TLD_INFO_SOURCE_END_CLASS,\FILE_APPEND)) { static::_echo_error("(FATAL) failed to write to new 'TldInfo.php' file",1); } echo "done\n"; if ($existingMd5!==null) { $newTldInfoMd5 = md5_file($newTldInfoFile); if ($existingMd5 == $newTldInfoMd5) { static::_echo_error("(NOTICE) ignoring newly generated 'TldInfo.php' file that is identical to the existing file (md5: $existingMd5, path: $tldInfoFile)"); return; } if (!unlink($tldInfoFile)) { static::_echo_error("(FATAL) failed to remove stale 'TldInfo.php': $tldInfoFile",1); } } if (!copy($newTldInfoFile,$tldInfoFile)) { static::_echo_error("(FATAL) failed to save new 'TldInfo.php': $tldInfoFile",1); } echo "saved new 'TldInfo.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_INFO_SOURCE_START_CLASS = <<&\$val) { if (isset(\$info[\$prop])) { \$val = \$info[\$prop]; } } unset(\$prop); unset(\$val); return \$infoItem; } } SOURCE; };