Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
* configuration file of ownCloud.
*/
class Config {

const ENV_PREFIX = 'OC_';

/** @var array Associative array ($key => $value) */
protected $cache = array();
/** @var string */
Expand Down Expand Up @@ -70,15 +73,22 @@ public function getKeys() {
}

/**
* 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];
}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function testGetValue() {
$this->assertSame(array('Appenzeller', 'Guinness', 'Kölsch'), $this->config->getValue('beers'));
}

public function testGetValueReturnsEnvironmentValueIfSet() {
$this->assertEquals('bar', $this->config->getValue('foo'));
putenv('OC_foo=baz');
$this->assertEquals('baz', $this->config->getValue('foo'));
}

public function testSetValue() {
$this->config->setValue('foo', 'moo');
$expectedConfig = $this->initialConfig;
Expand Down