diff options
author | Philipp Schaffrath <github@philipp.schaffrath.email> | 2017-01-24 12:18:29 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-04-04 15:56:50 -0500 |
commit | 695a17804ed261980e9c3c20a588c1f3a3a3507f (patch) | |
tree | b88fc16ee374cf2ee0c00aa00eeacaa84ea6e9fb /lib/private/Config.php | |
parent | fa4107893de4e94020dc1b3182cfea969b5db1a6 (diff) | |
download | nextcloud-server-695a17804ed261980e9c3c20a588c1f3a3a3507f.tar.gz nextcloud-server-695a17804ed261980e9c3c20a588c1f3a3a3507f.zip |
Override config.php values through ENV variables (#26570)
* added functionality to override config.php values with 'OC_' prefixed environment variables
* use getenv to read environment variables since apache does not set $_ENV variables, fixed test
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/Config.php')
-rw-r--r-- | lib/private/Config.php | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/private/Config.php b/lib/private/Config.php index e6a27a76b2e..28d8c560c5d 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -39,6 +39,9 @@ namespace OC; * configuration file of ownCloud. */ class Config { + + const ENV_PREFIX = 'OC_'; + /** @var array Associative array ($key => $value) */ protected $cache = array(); /** @var string */ @@ -71,15 +74,22 @@ class Config { } /** - * Gets a value from config.php + * Returns a config value * - * If it does not exist, $default will be returned. + * gets its value from an `OC_` prefixed environment variable + * if it doesn't exist from config.php + * if this doesn't exist either, it will return the given `$default` * * @param string $key key * @param mixed $default = null default value * @return mixed the value or $default */ public function getValue($key, $default = null) { + $envValue = getenv(self::ENV_PREFIX . $key); + if ($envValue) { + return $envValue; + } + if (isset($this->cache[$key])) { return $this->cache[$key]; } |