getRealPath(); // 1. Exclude the script itself and the output file. if ($file->getBasename() === 'llmdumper.php' || $file->getBasename() === OUTPUT_FILE) { continue; } // 2. Exclude the entire 'vendor' directory. // We check if the path contains '/vendor/'. if (strpos($filePath, DIRECTORY_SEPARATOR . VENDOR_DIR . DIRECTORY_SEPARATOR) !== false) { continue; } if (strpos($filePath, DIRECTORY_SEPARATOR . GIT_DIR . DIRECTORY_SEPARATOR) !== false) { continue; } // We only care about files, not directories. if ($file->isDir()) { continue; } // 3. Exclude image files based on their extension. $extension = strtolower($file->getExtension()); if (in_array($extension, IMAGE_EXTENSIONS)) { continue; } // --- File Processing --- // Get the file path relative to the module's root directory. $relativePath = str_replace($moduleRootPath . DIRECTORY_SEPARATOR, '', $filePath); // Prepend the module directory name to the relative path as requested. $finalPath = $moduleDirName . DIRECTORY_SEPARATOR . $relativePath; // Read the file content. $content = file_get_contents($filePath); if ($content === false) { echo "WARNING: Could not read file: {$finalPath}\n"; continue; } // Create a header for this file's content to identify it in the dump. $fileHeader = " //- - - - - - - - - - START: {$finalPath} - - - - - - - - - -// "; $fileFooter = " //- - - - - - - - - - END: {$finalPath} - - - - - - - - - -// \n"; // Assemble the full string to append to the output file. $dumpContent = $fileHeader . $content . $fileFooter; // Append the content to the output file. if (file_put_contents($outputFilePath, $dumpContent, FILE_APPEND)) { echo "Appended: {$finalPath}\n"; $totalBytes += strlen($dumpContent); $fileCount++; } else { echo "ERROR: Could not write to output file!\n"; exit(1); // Exit with an error code. } } echo "---------------------------------------------------\n"; echo "Dump complete!\n"; echo "- Files processed: {$fileCount}\n"; echo "- Total size: " . round($totalBytes / 1024, 2) . " KB\n"; echo "- Output file: {$outputFilePath}\n";