From 0443c8f674275cd44cd1221ee1c3703ad36ee37c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 29 Feb 2024 11:56:17 -0100 Subject: [PATCH] fix(appconfig): format app values Signed-off-by: Maxence Lange --- lib/private/AppConfig.php | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 518ba6ebf7a01..42966d3ea10ed 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -219,8 +219,9 @@ public function getAllValues(string $app, string $prefix = '', bool $filtered = // 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 @@ public function searchValues(string $key, bool $lazy = false): array { 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 @@ public function getFilteredValues($app) { 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 *