Skip to content

Commit cf673bc

Browse files
committed
fix(appconfig): format app values
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent fa0e3d6 commit cf673bc

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

lib/private/AppConfig.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ public function getAllValues(string $app, string $prefix = '', bool $filtered =
215215
// if we want to filter values, we need to get sensitivity
216216
$this->loadConfigAll();
217217
// array_merge() will remove numeric keys (here config keys), so addition arrays instead
218+
$values = $this->formatAppValues($app, ($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? []));
218219
$values = array_filter(
219-
(($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? [])),
220+
$values,
220221
function (string $key) use ($prefix): bool {
221222
return str_starts_with($key, $prefix); // filter values based on $prefix
222223
}, ARRAY_FILTER_USE_KEY
@@ -267,7 +268,8 @@ public function searchValues(string $key, bool $lazy = false): array {
267268

268269
foreach (array_keys($cache) as $app) {
269270
if (isset($cache[$app][$key])) {
270-
$values[$app] = $cache[$app][$key];
271+
$appCache = $this->formatAppValues((string)$app, $cache[$app]);
272+
$values[$app] = $appCache[$key];
271273
}
272274
}
273275

@@ -1337,6 +1339,38 @@ public function getFilteredValues($app) {
13371339
return $this->getAllValues($app, filtered: true);
13381340
}
13391341

1342+
1343+
/**
1344+
* @param string $app
1345+
* @param array $values
1346+
*
1347+
* @return array
1348+
*/
1349+
private function formatAppValues(string $app, array $values): array {
1350+
foreach($values as $key => $value) {
1351+
switch ($this->getValueType($app, $key)) {
1352+
case self::VALUE_INT:
1353+
$values[$key] = (int)$value;
1354+
break;
1355+
case self::VALUE_FLOAT:
1356+
$values[$key] = (float)$value;
1357+
break;
1358+
case self::VALUE_BOOL:
1359+
$values[$key] = in_array(strtolower($value), ['1', 'true', 'yes', 'on']);
1360+
break;
1361+
case self::VALUE_ARRAY:
1362+
try {
1363+
$values[$key] = json_decode($value, true, flags: JSON_THROW_ON_ERROR);
1364+
} catch (JsonException $e) {
1365+
// ignoreable
1366+
}
1367+
break;
1368+
}
1369+
}
1370+
1371+
return $values;
1372+
}
1373+
13401374
/**
13411375
* @param string $app
13421376
*

0 commit comments

Comments
 (0)