mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #46140 from nextcloud/fix-nc-env-inclusion
fix(config): Add missing handling for `envCache` in `getKeys()`
This commit is contained in:
commit
d9c5512878
2 changed files with 20 additions and 5 deletions
|
|
@ -49,7 +49,7 @@ class Config {
|
|||
* @return array an array of key names
|
||||
*/
|
||||
public function getKeys() {
|
||||
return array_keys($this->cache);
|
||||
return array_merge(array_keys($this->cache), array_keys($this->envCache));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,9 +64,8 @@ class Config {
|
|||
* @return mixed the value or $default
|
||||
*/
|
||||
public function getValue($key, $default = null) {
|
||||
$envKey = self::ENV_PREFIX . $key;
|
||||
if (isset($this->envCache[$envKey])) {
|
||||
return $this->envCache[$envKey];
|
||||
if (isset($this->envCache[$key])) {
|
||||
return $this->envCache[$key];
|
||||
}
|
||||
|
||||
if (isset($this->cache[$key])) {
|
||||
|
|
@ -226,7 +225,16 @@ class Config {
|
|||
}
|
||||
}
|
||||
|
||||
$this->envCache = getenv();
|
||||
// grab any "NC_" environment variables
|
||||
$envRaw = getenv();
|
||||
// only save environment variables prefixed with "NC_" in the cache
|
||||
$envPrefixLen = strlen(self::ENV_PREFIX);
|
||||
foreach ($envRaw as $rawEnvKey => $rawEnvValue) {
|
||||
if (str_starts_with($rawEnvKey, self::ENV_PREFIX)) {
|
||||
$realKey = substr($rawEnvKey, $envPrefixLen);
|
||||
$this->envCache[$realKey] = $rawEnvValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,6 +41,13 @@ class ConfigTest extends TestCase {
|
|||
$this->assertSame($expectedConfig, $this->getConfig()->getKeys());
|
||||
}
|
||||
|
||||
public function testGetKeysReturnsEnvironmentKeysIfSet() {
|
||||
$expectedConfig = ['foo', 'beers', 'alcohol_free', 'taste'];
|
||||
putenv('NC_taste=great');
|
||||
$this->assertSame($expectedConfig, $this->getConfig()->getKeys());
|
||||
putenv('NC_taste');
|
||||
}
|
||||
|
||||
public function testGetValue(): void {
|
||||
$config = $this->getConfig();
|
||||
$this->assertSame('bar', $config->getValue('foo'));
|
||||
|
|
|
|||
Loading…
Reference in a new issue