aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--WpfTest/Db.php3
-rw-r--r--WpfTest/GlobalConfig.php34
-rw-r--r--config.ini20
4 files changed, 55 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index a725465..759b342 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-vendor/ \ No newline at end of file
+vendor/
+config.ini \ No newline at end of file
diff --git a/WpfTest/Db.php b/WpfTest/Db.php
index 3de1011..799332f 100644
--- a/WpfTest/Db.php
+++ b/WpfTest/Db.php
@@ -9,7 +9,8 @@ class Db extends Singleton {
private \PDO $conn;
protected function __construct() {
- $this->conn = new \PDO('pgsql:host=localhost;dbname=wpftest', 'wpftest', 'wpftest', [
+ $conf = GlobalConfig::getInstance();
+ $this->conn = new \PDO($conf->getDbConnection(), $conf->getDbUser(), $conf->getDbPassword(), [
\PDO::ATTR_PERSISTENT => true,
]);
}
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
diff --git a/config.ini b/config.ini
new file mode 100644
index 0000000..a09203f
--- /dev/null
+++ b/config.ini
@@ -0,0 +1,20 @@
+[instance]
+; hostname (required) and port (optional) should be the values seen from the
+; outside world. this is important if you're using a reverse proxy
+hostname = example.com
+;port = 443
+; whether clients will use https to connect - again, important for reverse
+; proxies that terminate tls (optional, default = true)
+;https = false
+
+[database]
+host = localhost
+port = 5432
+username = wpftest
+password = wpftest
+database = wpftest
+
+[debug]
+; whether to send full tracebacks on internal server errors (optional,
+; default = false)
+;send_tracebacks = true \ No newline at end of file