diff --git a/.gitignore b/.gitignore index eaf169cb8..9a3d01c23 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ Thumbs.db .idea/* plugins.local/* themes.local/* -config.php +/config.php feed-icons/* cache/*/* lock/* diff --git a/classes/config.php b/classes/config.php new file mode 100644 index 000000000..8a7470135 --- /dev/null +++ b/classes/config.php @@ -0,0 +1,98 @@ + "pgsql", + Config::DB_HOST => "db", + Config::DB_USER => "", + Config::DB_NAME => "", + Config::DB_PASS => "", + Config::DB_PORT => "5432", + Config::MYSQL_CHARSET => "UTF8", + Config::SELF_URL_PATH => "", + Config::SINGLE_USER_MODE => "", + Config::SIMPLE_UPDATE_MODE => "", + Config::PHP_EXECUTABLE => "/usr/bin/php", + Config::LOCK_DIRECTORY => "lock", + Config::CACHE_DIR => "cache", + Config::ICONS_DIR => "feed-icons", + Config::ICONS_URL => "feed-icons", + Config::AUTH_AUTO_CREATE => "true", + Config::AUTH_AUTO_LOGIN => "true", + Config::FORCE_ARTICLE_PURGE => 0, + Config::ENABLE_REGISTRATION => "", + Config::SESSION_COOKIE_LIFETIME => 86400, + Config::SMTP_FROM_NAME => "Tiny Tiny RSS", + Config::SMTP_FROM_ADDRESS => "noreply@localhost", + Config::DIGEST_SUBJECT => "[tt-rss] New headlines for last 24 hours", + Config::CHECK_FOR_UPDATES => "true", + Config::PLUGINS => "auth_internal", + Config::LOG_DESTINATION => "sql", + ]; + + private const _ENVVAR_PREFIX = "TTRSS_"; + private static $instance; + + private $params = []; + + public static function get_instance() { + if (self::$instance == null) + self::$instance = new self(); + + return self::$instance; + } + + function __construct() { + $ref = new ReflectionClass(get_class($this)); + + foreach ($ref->getConstants() as $const => $cvalue) { + if (strpos($const, "_") !== 0) { + $override = getenv($this::_ENVVAR_PREFIX . $const); + + if (!empty($override)) { + $this->params[$cvalue] = $override; + } else { + $this->params[$cvalue] = $this::_DEFAULTS[$const]; + } + } + } + } + + private function _get($param) { + return $this->params[$param]; + } + + static function get($param) { + $instance = self::get_instance(); + + return $instance->_get($param); + } + +} \ No newline at end of file