<?php
/**
* Boots internal tooling scripts with graceful failure handling.
*
* @param array $scripts An array of file paths to scripts to boot.
* @return void
*/
function bootstrapScripts(array $scripts): void
{
foreach ($scripts as $scriptPath) {
try {
// Check if the script file exists
if (!file_exists($scriptPath)) {
throw new Exception("Script file not found: " . $scriptPath);
}
// Include the script file
require_once $scriptPath;
// Optional: Add specific handling for each script if needed.
// For example, call a specific function.
// if (function_exists('my_tool_function')) {
// my_tool_function();
// }
} catch (Exception $e) {
// Log the error
error_log("Error booting script " . $scriptPath . ": " . $e->getMessage());
// Optionally, perform additional error handling, such as sending an email notification.
// Consider using a logging system like Monolog.
// Continue to the next script even if one fails.
}
}
}
// Example Usage
/*
$scriptsToBoot = [
'./scripts/script_one.php',
'./scripts/script_two.php',
'./scripts/nonexistent_script.php', // This will cause an error
];
bootstrapScripts($scriptsToBoot);
*/
?>
Add your comment