52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
|
|
<?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();
|