1. <?php
  2. /**
  3. * Boots internal tooling scripts with graceful failure handling.
  4. *
  5. * @param array $scripts An array of file paths to scripts to boot.
  6. * @return void
  7. */
  8. function bootstrapScripts(array $scripts): void
  9. {
  10. foreach ($scripts as $scriptPath) {
  11. try {
  12. // Check if the script file exists
  13. if (!file_exists($scriptPath)) {
  14. throw new Exception("Script file not found: " . $scriptPath);
  15. }
  16. // Include the script file
  17. require_once $scriptPath;
  18. // Optional: Add specific handling for each script if needed.
  19. // For example, call a specific function.
  20. // if (function_exists('my_tool_function')) {
  21. // my_tool_function();
  22. // }
  23. } catch (Exception $e) {
  24. // Log the error
  25. error_log("Error booting script " . $scriptPath . ": " . $e->getMessage());
  26. // Optionally, perform additional error handling, such as sending an email notification.
  27. // Consider using a logging system like Monolog.
  28. // Continue to the next script even if one fails.
  29. }
  30. }
  31. }
  32. // Example Usage
  33. /*
  34. $scriptsToBoot = [
  35. './scripts/script_one.php',
  36. './scripts/script_two.php',
  37. './scripts/nonexistent_script.php', // This will cause an error
  38. ];
  39. bootstrapScripts($scriptsToBoot);
  40. */
  41. ?>

Add your comment