diff options
| author | winter | 2024-12-09 21:31:54 +0000 |
|---|---|---|
| committer | winter | 2024-12-09 21:31:54 +0000 |
| commit | 4c7bde1400820f36caf8b2a5374007384c3018f3 (patch) | |
| tree | 83ed26ff368117b8e392f7bc28736482077fc2f4 /Digitigrade/GlobalConfig.php | |
| parent | 50edbd3907c26a2d4d616421de9bb51a4d083c1b (diff) | |
rename to Digitigrade / PawPub
:3
Diffstat (limited to 'Digitigrade/GlobalConfig.php')
| -rw-r--r-- | Digitigrade/GlobalConfig.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Digitigrade/GlobalConfig.php b/Digitigrade/GlobalConfig.php new file mode 100644 index 0000000..f17b758 --- /dev/null +++ b/Digitigrade/GlobalConfig.php @@ -0,0 +1,44 @@ +<?php +namespace Digitigrade; + +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 { + $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['debug']['https'] ?? true; + } + + public function getBasePath(): string { + return ($this->isHttps() ? 'https://' : 'http://') . $this->getCanonicalHost(); + } + + public function shouldReportTraces(): bool { + 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 |
