<?php
/**
* Bootstrap script loader for a local utility.
*/
// Set error reporting level
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Define the base directory for scripts
define('BASE_DIR', __DIR__);
/**
* Autoloads classes from specified directories.
*
* @param string $directory The directory to scan for classes.
*/
function autoload($directory) {
$files = glob($directory . '/*.php'); //Get all php files in the directory
foreach ($files as $file) {
if (is_readable($file)) {
require_once $file; //Include the class definition
}
}
}
// Register the autoloader
spl_autoload_register('autoload');
/**
* Registers runtime environment scripts.
*/
function registerRuntimeEnvironment() {
// Register required environment scripts
require_once BASE_DIR . '/config.php'; //Configuration settings
require_once BASE_DIR . '/db.php'; //Database connection
require_once BASE_DIR . '/helpers.php'; //Utility functions
require_once BASE_DIR . '/utils.php'; //General utility functions
// Register any other runtime scripts here
}
// Initialize the runtime environment
registerRuntimeEnvironment();
//Enable Logging
function logMessage($message, $level = 'INFO') {
$timestamp = date('Y-m-d H:i:s');
$logEntry = "[$timestamp] [$level] $message\n";
file_put_contents(BASE_DIR . '/log.txt', $logEntry, FILE_APPEND);
}
// Example usage
logMessage('Utility started successfully.');
?>
Add your comment