1. <?php
  2. /**
  3. * Bootstrap script loader for a local utility.
  4. */
  5. // Set error reporting level
  6. error_reporting(E_ALL);
  7. ini_set('display_errors', 1);
  8. // Define the base directory for scripts
  9. define('BASE_DIR', __DIR__);
  10. /**
  11. * Autoloads classes from specified directories.
  12. *
  13. * @param string $directory The directory to scan for classes.
  14. */
  15. function autoload($directory) {
  16. $files = glob($directory . '/*.php'); //Get all php files in the directory
  17. foreach ($files as $file) {
  18. if (is_readable($file)) {
  19. require_once $file; //Include the class definition
  20. }
  21. }
  22. }
  23. // Register the autoloader
  24. spl_autoload_register('autoload');
  25. /**
  26. * Registers runtime environment scripts.
  27. */
  28. function registerRuntimeEnvironment() {
  29. // Register required environment scripts
  30. require_once BASE_DIR . '/config.php'; //Configuration settings
  31. require_once BASE_DIR . '/db.php'; //Database connection
  32. require_once BASE_DIR . '/helpers.php'; //Utility functions
  33. require_once BASE_DIR . '/utils.php'; //General utility functions
  34. // Register any other runtime scripts here
  35. }
  36. // Initialize the runtime environment
  37. registerRuntimeEnvironment();
  38. //Enable Logging
  39. function logMessage($message, $level = 'INFO') {
  40. $timestamp = date('Y-m-d H:i:s');
  41. $logEntry = "[$timestamp] [$level] $message\n";
  42. file_put_contents(BASE_DIR . '/log.txt', $logEntry, FILE_APPEND);
  43. }
  44. // Example usage
  45. logMessage('Utility started successfully.');
  46. ?>

Add your comment