'.PHP_EOL, $argv[0]); exit(1); } [$src, $dst] = [$argv[1], $argv[2]]; $srcPath = new \SplFileInfo($src); $dstPath = new \SplFileInfo($dst); // Validate the source path if ($srcPath->getRealPath() === false) { printf('The source path "%s" does not exist.'.PHP_EOL, $srcPath->getPathname()); exit(1); } if ($srcPath->isDir() === false) { printf('The source path "%s" is not a directory.'.PHP_EOL, $srcPath->getPathname()); exit(1); } // Validate the destination path if ($dstPath->getRealPath() === false) { printf('The destination path "%s" does not exist.'.PHP_EOL, $dstPath->getPathname()); exit(1); } if ($dstPath->isDir() === false) { printf('The destination path "%s" is not a directory.'.PHP_EOL, $dstPath->getPathname()); exit(1); } $iterator = new \RecursiveIteratorIterator(new \RecursiveCallbackFilterIterator( new \RecursiveDirectoryIterator($srcPath->getRealPath(), \FilesystemIterator::SKIP_DOTS), static function (\SplFileInfo $file) use ($srcPath): bool { if ($file->isDir()) { $relativePath = substr($file->getRealPath(), strlen($srcPath->getRealPath())); return str_starts_with($relativePath, DIRECTORY_SEPARATOR.'en_us') || str_starts_with($relativePath, DIRECTORY_SEPARATOR.'zh_cn'); } return $file->isFile() && $file->getExtension() === 'json'; } )); foreach ($iterator as $file) { $relativePath = substr($file->getRealPath(), strlen($srcPath->getRealPath())); printf('[-] Generate %s'.PHP_EOL, $relativePath); // Change the file extension from json to php $out = $dstPath->getRealPath().substr($relativePath, 0, -4).'php'; $outdir = dirname($out); if (! file_exists($outdir)) { mkdir($outdir, 0o755, recursive: true); } $contents = file_get_contents($file->getRealPath()); $decoded = json_decode($contents, associative: true, flags: JSON_THROW_ON_ERROR); $result = sprintf('