summaryrefslogtreecommitdiff
path: root/classes/config.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-22 23:20:52 +0300
committerAndrew Dolgov <[email protected]>2021-02-22 23:20:52 +0300
commit77e6d589ffdf4ddb381f0b63b319e59bacfff1e8 (patch)
treef772203f8b8a83e83efb63ef0c5a5240a663e9ae /classes/config.php
parentfd5dd27f16fe7da3ca6399501d81022ee2659124 (diff)
allow adding custom config options
Diffstat (limited to 'classes/config.php')
-rw-r--r--classes/config.php28
1 files changed, 17 insertions, 11 deletions
diff --git a/classes/config.php b/classes/config.php
index b154206da..6f62863e9 100644
--- a/classes/config.php
+++ b/classes/config.php
@@ -2,9 +2,7 @@
class Config {
private const _ENVVAR_PREFIX = "TTRSS_";
- // TODO: this should be extensible so plugins could add their own global directives (with defaults)
-
- // overriding defaults (defined below in _DEFAULTS[]) via environment: DB_TYPE becomes TTRSS_DB_TYPE, etc
+ // override defaults, defined below in _DEFAULTS[], via environment: DB_TYPE becomes TTRSS_DB_TYPE, etc
const DB_TYPE = "DB_TYPE";
const DB_HOST = "DB_HOST";
@@ -114,23 +112,31 @@ class Config {
if (strpos($const, "_") !== 0) {
$override = getenv($this::_ENVVAR_PREFIX . $const);
- if (!empty($override)) {
- $this->params[$cvalue] = $override;
- } else {
- $this->params[$cvalue] = $this::_DEFAULTS[$const];
- }
+ $this->params[$cvalue] = !empty($override) ? $override : $this::_DEFAULTS[$const];
}
}
}
- private function _get($param) {
+ private function _get(string $param) {
return $this->params[$param];
}
- static function get($param) {
+ private function _add(string $param, string $default) {
+ $override = getenv($this::_ENVVAR_PREFIX . $param);
+
+ $this->params[$param] = !empty($override) ? $override : $default;
+ }
+
+ static function add(string $param, string $default) {
+ $instance = self::get_instance();
+
+ return $instance->_add($param, $default);
+ }
+
+ static function get(string $param) {
$instance = self::get_instance();
return $instance->_get($param);
}
-} \ No newline at end of file
+}