diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-02-29 11:56:17 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-03-15 08:46:00 -0100 |
commit | 76b4dbce8cb1f486ce22c5a57484159cffae0fb4 (patch) | |
tree | af13f8113e1a47fd79f6426a1086b68c529276a8 | |
parent | df1cd1ba7e6e1f6e66a2b3229b5c082f1b81162e (diff) | |
download | nextcloud-server-enh/noid/returns-formated-app-values-2.tar.gz nextcloud-server-enh/noid/returns-formated-app-values-2.zip |
fix(appconfig): format app valuesenh/noid/returns-formated-app-values-2
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/private/AppConfig.php | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 518ba6ebf7a..42966d3ea10 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -219,8 +219,9 @@ class AppConfig implements IAppConfig { // if we want to filter values, we need to get sensitivity $this->loadConfigAll(); // array_merge() will remove numeric keys (here config keys), so addition arrays instead + $values = $this->formatAppValues($app, ($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? [])); $values = array_filter( - (($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? [])), + $values, function (string $key) use ($prefix): bool { return str_starts_with($key, $prefix); // filter values based on $prefix }, ARRAY_FILTER_USE_KEY @@ -271,7 +272,8 @@ class AppConfig implements IAppConfig { foreach (array_keys($cache) as $app) { if (isset($cache[$app][$key])) { - $values[$app] = $cache[$app][$key]; + $appCache = $this->formatAppValues((string)$app, $cache[$app]); + $values[$app] = $appCache[$key]; } } @@ -1386,6 +1388,38 @@ class AppConfig implements IAppConfig { return $this->getAllValues($app, filtered: true); } + + /** + * @param string $app + * @param array $values + * + * @return array + */ + private function formatAppValues(string $app, array $values): array { + foreach($values as $key => $value) { + switch ($this->getValueType($app, $key)) { + case self::VALUE_INT: + $values[$key] = (int)$value; + break; + case self::VALUE_FLOAT: + $values[$key] = (float)$value; + break; + case self::VALUE_BOOL: + $values[$key] = in_array(strtolower($value), ['1', 'true', 'yes', 'on']); + break; + case self::VALUE_ARRAY: + try { + $values[$key] = json_decode($value, true, flags: JSON_THROW_ON_ERROR); + } catch (JsonException $e) { + // ignoreable + } + break; + } + } + + return $values; + } + /** * @param string $app * |