tkr/config/bootstrap.php
Greg Sarjeant d3a537aa6c Fix first-time setup issues. (#68)
Fixes for issues found testing first time setup in the different configurations.

Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/68
Co-authored-by: Greg Sarjeant <greg@subcultureofone.org>
Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
2025-08-13 12:02:37 +00:00

47 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
// This is the initialization code that needs to be run before anything else.
// - define paths
// - set up autoloader
// Set a couple ini settings for security
ini_set('allow_url_fopen', 0); // don't allow remote files to be read
ini_set('expose_php', 0); // don't advertise the PHP version
// Define all the important paths
define('APP_ROOT', dirname(dirname(__FILE__)));
// Root-level directories
define('CONFIG_DIR', APP_ROOT . '/config');
define('PUBLIC_DIR', APP_ROOT . '/public');
define('SRC_DIR', APP_ROOT . '/src');
define('STORAGE_DIR', APP_ROOT . '/storage');
// Storage subdirectories
define('CSS_UPLOAD_DIR', STORAGE_DIR . '/upload/css');
define('DATA_DIR', STORAGE_DIR . '/db');
define('TEMPLATES_DIR', APP_ROOT . '/templates');
// Database file
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
);
// I'm just going to let this fail hard if a requested class doesn't exist.
foreach ($files as $file) {
if ($file->getFilename() === $classFilename) {
include_once $file->getPathname();
return;
}
}
}
// Register the autoloader
spl_autoload_register('autoloader');