Added files

This commit is contained in:
Holger Sielaff
2025-06-28 16:23:47 +02:00
parent 21a2714401
commit e2eeeaefcd
8 changed files with 328 additions and 0 deletions

51
bootstrap.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
ini_set('display_errors', false);
if ( ! file_exists(__DIR__ . '/.env.local') ){
copy(__DIR__ . '/.env', __DIR__ . '/.env.local');
}
$_allowed = range('A', 'Z');
foreach(file(__DIR__ . '/.env.local') as $line){
$line = trim($line);
if ( ! in_array($line[0], $_allowed) ) {
continue;
}
putenv($line);
}
class Config {
private static PDO $_pdo;
public static function dbName() {
return getenv('DBNAME') ?: 'track';
}
public static function dbUser() {
return getenv('DBUSER') ?: 'track';
}
public static function dbPass() {
return getenv('DBPASS') ?: 'track';
}
public static function apiHost() {
return getenv('APIHOST') ?: 'www.example.com';
}
public static function apiKey() {
return getenv('APIKEY') ?: 'xxx';
}
public static function isVerbose() {
return intval(getenv('VERBOSE')) ?: 0;
}
public static function dbConnection(): PDO {
if(!self::$_pdo) {
self::$_pdo = new PDO(
sprintf("pgsql:dbname=%s;host=127.0.0.1", Config::dbName()),
COnfig::dbUser(),
COnfig::dbPass(),
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]
);
}
return self::$_pdo;
}
}
$pdo = Config::dbConnection();