tkr/config/bootstrap.php
2025-06-30 08:43:45 -04:00

42 lines
1.3 KiB
PHP

<?php
// This is the initialization code that needs to be run before anything else.
// - define paths
// - set up autoloader
// Define all the important paths
define('APP_ROOT', dirname(dirname(__FILE__)));
define('CONFIG_DIR', APP_ROOT . '/config');
define('SRC_DIR', APP_ROOT . '/src');
define('STORAGE_DIR', APP_ROOT . '/storage');
define('TEMPLATES_DIR', APP_ROOT . '/templates');
define('TICKS_DIR', STORAGE_DIR . '/ticks');
define('DATA_DIR', STORAGE_DIR . '/db');
define('CSS_UPLOAD_DIR', STORAGE_DIR . '/upload/css');
define('DB_FILE', DATA_DIR . '/tkr.sqlite');
// Janky autoloader function
// This is a bit more consistent with current frameworks
function autoloader($className) {
$classFilename = $className . '.php';
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(SRC_DIR, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file) {
if ($file->getFilename() === $classFilename) {
include_once $file->getPathname();
return;
}
}
throw new SetupException(
"Could not load Class $className: " . $e->getMessage(),
'load_classes'
);
}
// Register the autoloader
spl_autoload_register('autoloader');