diff options
Diffstat (limited to 'WpfTest/GlobalConfig.php')
| -rw-r--r-- | WpfTest/GlobalConfig.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/WpfTest/GlobalConfig.php b/WpfTest/GlobalConfig.php index 03cfe6f..b5bb9df 100644 --- a/WpfTest/GlobalConfig.php +++ b/WpfTest/GlobalConfig.php @@ -2,15 +2,43 @@ namespace WpfTest; class GlobalConfig extends Singleton { + private const CONFIG_INI_PATH = __DIR__ . '/../config.ini'; + private array $confData; + + protected function __construct() { + $this->confData = parse_ini_file(self::CONFIG_INI_PATH, process_sections: true); + } + public function getCanonicalHost(): string { - return $_SERVER['HTTP_HOST']; // for now this is fine + $host = $this->confData['instance']['hostname']; + if (isset($this->confData['instance']['port']) && $this->confData['instance']['port'] != ($this->isHttps() ? 443 : 80)) + $host .= ':' . $this->confData['instance']['port']; + return $host; + } + + public function isHttps(): bool { + return $this->confData['instance']['https'] ?? true; } public function getBasePath(): string { - return 'http://' . $this->getCanonicalHost(); // FIXME: don't hardcode http + return ($this->isHttps() ? 'https://' : 'http://') . $this->getCanonicalHost(); } public function shouldReportTraces(): bool { - return true; // FIXME: don't hardcode + return $this->confData['debug']['send_tracebacks'] ?? false; + } + + public function getDbConnection(): string { + return 'pgsql:host=' . $this->confData['database']['host'] . + ';port=' . $this->confData['database']['port'] . + ';dbname=' . $this->confData['database']['database']; + } + + public function getDbUser(): string { + return $this->confData['database']['username']; + } + + public function getDbPassword(): string { + return $this->confData['database']['password']; } }
\ No newline at end of file |
