Skip to content

Commit 43338de

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

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

lib/private/AppConfig.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public function searchValues(string $key, bool $lazy = false): array {
271271

272272
foreach (array_keys($cache) as $app) {
273273
if (isset($cache[$app][$key])) {
274-
$values[$app] = $cache[$app][$key];
274+
$appCache = $this->formatAppValues((string)$app, $cache[$app], $lazy);
275+
$values[$app] = $appCache[$key];
275276
}
276277
}
277278

@@ -510,9 +511,9 @@ private function getTypedValue(
510511
* @see VALUE_BOOL
511512
* @see VALUE_ARRAY
512513
*/
513-
public function getValueType(string $app, string $key): int {
514+
public function getValueType(string $app, string $key, ?bool $lazy = null): int {
514515
$this->assertParams($app, $key);
515-
$this->loadConfigAll();
516+
$this->loadConfig($lazy);
516517

517518
if (!isset($this->valueTypes[$app][$key])) {
518519
throw new AppConfigUnknownKeyException('unknown config key');
@@ -1393,9 +1394,15 @@ public function getFilteredValues($app) {
13931394
*
13941395
* @return array
13951396
*/
1396-
private function formatAppValues(string $app, array $values): array {
1397+
private function formatAppValues(string $app, array $values, ?bool $lazy = null): array {
13971398
foreach($values as $key => $value) {
1398-
switch ($this->getValueType($app, $key)) {
1399+
try {
1400+
$type = $this->getValueType($app, $key, $lazy);
1401+
} catch (AppConfigUnknownKeyException $e) {
1402+
continue; // ignorable
1403+
}
1404+
1405+
switch ($type) {
13991406
case self::VALUE_INT:
14001407
$values[$key] = (int)$value;
14011408
break;

lib/public/IAppConfig.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ public function getValueArray(string $app, string $key, array $default = [], boo
261261
* returns the type of config value
262262
*
263263
* **WARNING:** ignore lazy filtering, all config values are loaded from database
264+
* unless lazy is set to false
264265
*
265266
* @param string $app id of the app
266267
* @param string $key config key
268+
* @param bool|null $lazy
267269
*
268270
* @return int
269271
* @throws AppConfigUnknownKeyException
@@ -274,7 +276,7 @@ public function getValueArray(string $app, string $key, array $default = [], boo
274276
* @see VALUE_BOOL
275277
* @see VALUE_ARRAY
276278
*/
277-
public function getValueType(string $app, string $key): int;
279+
public function getValueType(string $app, string $key, ?bool $lazy = null): int;
278280

279281
/**
280282
* Store a config key and its value in database

0 commit comments

Comments
 (0)