summaryrefslogtreecommitdiff
path: root/classes/config.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/config.php')
-rw-r--r--classes/config.php27
1 files changed, 23 insertions, 4 deletions
diff --git a/classes/config.php b/classes/config.php
index effbb78ad..ee1d3cb4a 100644
--- a/classes/config.php
+++ b/classes/config.php
@@ -107,14 +107,19 @@ class Config {
private static $instance;
private $params = [];
+ private $schema_version = null;
- public static function get_instance() {
+ public static function get_instance() : Config {
if (self::$instance == null)
self::$instance = new self();
return self::$instance;
}
+ private function __clone() {
+ //
+ }
+
function __construct() {
$ref = new ReflectionClass(get_class($this));
@@ -124,12 +129,26 @@ class Config {
list ($defval, $deftype) = $this::_DEFAULTS[$const];
- $this->params[$cvalue] = [ $this->cast_to(!empty($override) ? $override : $defval, $deftype), $deftype ];
+ $this->params[$cvalue] = [ self::cast_to(!empty($override) ? $override : $defval, $deftype), $deftype ];
}
}
}
- private function cast_to(string $value, int $type_hint) {
+ static function get_schema_version(bool $nocache = false) {
+ return self::get_instance()->_schema_version($nocache);
+ }
+
+ function _schema_version(bool $nocache = false) {
+ if (empty($this->schema_version) || $nocache) {
+ $row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
+
+ $this->schema_version = (int) $row["schema_version"];
+ }
+
+ return $this->schema_version;
+ }
+
+ static function cast_to(string $value, int $type_hint) {
switch ($type_hint) {
case self::T_BOOL:
return sql_bool_to_bool($value);
@@ -149,7 +168,7 @@ class Config {
private function _add(string $param, string $default, int $type_hint) {
$override = getenv($this::_ENVVAR_PREFIX . $param);
- $this->params[$param] = [ $this->cast_to(!empty($override) ? $override : $default, $type_hint), $type_hint ];
+ $this->params[$param] = [ self::cast_to(!empty($override) ? $override : $default, $type_hint), $type_hint ];
}
static function add(string $param, string $default, int $type_hint = Config::T_STRING) {