summaryrefslogtreecommitdiffstats
path: root/lib/private/Config.php
diff options
context:
space:
mode:
authorPhilipp Schaffrath <github@philipp.schaffrath.email>2017-01-24 12:18:29 +0100
committerMorris Jobke <hey@morrisjobke.de>2017-04-04 15:56:50 -0500
commit695a17804ed261980e9c3c20a588c1f3a3a3507f (patch)
treeb88fc16ee374cf2ee0c00aa00eeacaa84ea6e9fb /lib/private/Config.php
parentfa4107893de4e94020dc1b3182cfea969b5db1a6 (diff)
downloadnextcloud-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.php14
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];
}